[转载]SWFUpload插件+FTP文件上传,我这么玩 – Ar.Issac – 博客园
- ASP.NET
- 2015-04-13
- 77热度
- 0评论
[转载]SWFUpload插件+FTP文件上传,我这么玩 - Ar.Issac - 博客园.
效果图:









[code]
private FtpStatusCode FtpUpload(string sFileDstPath, string FolderName, string ftpServerIP, string ftpUserName, string ftpPwd)
{
try
{
FileInfo fileInf = new FileInfo(sFileDstPath);
FtpWebRequest reqFTP;
FtpWebResponse uploadResponse = null;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + FolderName + "/" + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
using (FileStream fs = fileInf.OpenRead())
{
using (Stream strm = reqFTP.GetRequestStream())
{
contentLen = fs.Read(buff, 0, buffLength);
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
}
}
uploadResponse = (FtpWebResponse)reqFTP.GetResponse();
return uploadResponse.StatusCode;
}
catch (Exception e)
{
return FtpStatusCode.Undefined;
throw new Exception("Ftp错误", e);
}
}
[/code]
后台代码,根据项目加入了上传FTP及插入数据库:





[code]
function fileDialogComplete1(numFilesSelected, numFilesQueued) {
try {
var info = $('#info').val();
if (numFilesQueued > 0) {
if (info == "") {
alert("信息不能为空");
swfu.cancelUpload();
return;
}
//在上传文件中加入自定义参数,用于后台接收处理
var postParams = {
'info': info
};
swfu.setPostParams(postParams);
if (numFilesSelected > 0) {
document.getElementById(this.customSettings.cancelButtonId).disabled = false;
}
swfu.startUpload();
}
} catch (ex) {
this.debug(ex);
}
}
[/code]
实际上SWFupload可以玩的事件有很多,在handler.js文件中可以看到,如果需要控制某个事件可以直接修改,具体可见这篇文章:
SWFUpload 2.5.0版 官方说明文档 http://www.cnblogs.com/youring2/archive/2012/07/13/2590010.html