0
我使用此代碼上傳文件到FTP服務器:C# - 在FTP上傳文件不能正常工作
String source = @"E:\\file\e1.txt";
String ftpurl = @"ftp://ftp.myftpserver.pl";
String ftpusername = @"[email protected]";
String ftppassword = @"mypassword";
string filename = Path.GetFileName(source);
string ftpfullpath = ftpurl + "/" + filename;
Debug.WriteLine("Uploading...");
var fs = File.OpenRead(source);
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
ftp.Timeout = -1;
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
Stream ftpstream = ftp.GetRequestStream();
fs.CopyTo(ftpstream);
ftpstream.Close();
Debug.WriteLine("Upload complete.");
文件已退出大 - 約50萬桶。所以,上傳文件後,appliaction掛起。這是在調試窗口
Uploading... //immediately after executing the code
The thread 0xd50 has exited with code 0 (0x0). //after some time
輸出它從來沒有打印:
Upload complete.
注意,該線程退出後,上傳仍在進行中,它不會被取消。我已經注意到這個問題,當我試圖在循環中從List發送多個文件時 - 應用程序在上載第一個文件後掛起。 有人可以幫我嗎?
//編輯 出於測試目的,我試圖在for循環中上傳更小的文件。它似乎工作即使
The thread XXX has exited with code 0 (0x0).
所以這是因爲尺寸的,但我的服務器將接受更大的文件,我對FTP空間。有任何想法嗎?
把它放在try catch並讀取異常 – Tuco
沒有例外。 –
嘗試上傳更小尺寸的較小文件? – Jonesopolis