Winform 中 ftp多個文件上傳怎麼做

zhantianyou 2009-01-09 11:35:36
目前項目中要求一次性上傳多個文件到服務器,用Ftp怎麼做啊
有沒有只創建一條接,再把多個文件通過這個邊接上傳.
我現在是每上傳一個文件就創建一條連接,上傳完再關閉.但總感覺慢.因為在連接要花時間.

求教!!!!小弟謝了
...全文
145 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhantianyou 2009-01-09
  • 打赏
  • 举报
回复
是的,服務器是我們公司的
i0876 2009-01-09
  • 打赏
  • 举报
回复
除非服务器端也是你自己做的。。。
zhantianyou 2009-01-09
  • 打赏
  • 举报
回复
我說有沒有只用一個ftpWebrequest來做,現在每次都創建一條,這樣就花費時間在創建連接上了
i0876 2009-01-09
  • 打赏
  • 举报
回复
开线程来传。
zhantianyou 2009-01-09
  • 打赏
  • 举报
回复
能不能說下怎麼做啊,我也是用循環做的

Stream requestStream = null;
FileStream fileStream = null;
FtpWebResponse upLoadResponse = null;
int percent = 0;
try
{
string uriAllPath = uriUpLoad + fileAlias;
//這里每次都創建了一條連接,有什麼方法改變沒
FtpWebRequest upLoadRequest = (FtpWebRequest)WebRequest.Create(uriAllPath);
upLoadRequest.Method = WebRequestMethods.Ftp.UploadFile;
upLoadRequest.Proxy = null;
requestStream = upLoadRequest.GetRequestStream();

fileStream = File.OpenRead(filePath);
byte[] byteArr = new byte[1024];
int byteLen;
while (true)
{
if (worker.CancellationPending)
{
e.Cancel = true;
break;
}
byteLen = fileStream.Read(byteArr, 0, byteArr.Length);
if (byteLen == 0)
break;
requestStream.Write(byteArr, 0, byteLen);
numToComplete = numToComplete + byteLen;
percent = (int)((float)numToComplete / (float)(total*1024) * 100);
if (percent <= 100)
worker.ReportProgress(percent);
}
requestStream.Close();
upLoadResponse = (FtpWebResponse)upLoadRequest.GetResponse();
upLoadResponse.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (upLoadResponse != null)
upLoadResponse.Close();
if (requestStream != null)
requestStream.Close();
if (fileStream != null)
fileStream.Close();
}
這個是我做的.循環調用這個方法
冷月孤峰 2009-01-09
  • 打赏
  • 举报
回复
用循环来上传!

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧