0
我想上傳多個文件,但我只是嘗試單個文件上傳實踐,但我沒有找到文件異常我的任務是作爲下。FileNotFoundException與FTP
private static void UploadFileToFtp(string source)
{
String ftpurl = @"ftp://ftp.yuvarukhisamaj.com/wwwroot/Shtri/"; //「@ftpurl」; // e.g. ftp://serverip/foldername/foldername
String ftpusername = "yuvarukh";//「@ftpusername」; // e.g. username
String ftppassword = "CXhV5Rzeu";//「@ftppassword」; // e.g. password
try
{
string filename = Path.GetFileName(source);
string ftpfullpath = ftpurl;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(source);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
catch (Exception ex)
{
throw ex;
}
}
protected void Btn1_Click(object sender, EventArgs e)
{
String sourcefilepath = FileUpload1.FileName;
UploadFileToFtp(sourcefilepath);
}
錯誤詳情是An Exception of type 「System.IO.FileNotFoundException」 Occurred in Bshadow.DLL but was not handle in usercode
。 附加信息:找不到文件C:\Programfiles\Microsoft Visual Studio 8\IDE\dd.jpg
如何使用fileUploaders通過FTP上傳多個文件?
當您將C:\ Programfiles \ Microsoft Visual Studio 8 \ IDE \ dd.jpg粘貼到Windows資源管理器中時,您能看到該文件嗎? – Sefa
@vgSefa,它位於「E:\ Asp.Net Test \ YuvaRK12 \ YuvaRK12 \ Shtri \ dd.jpg」,但它在C:\ Programfiles \ Microsoft Visual Studio 8 \ IDE \ dd.jpg上不可用 – user2741987
@ user2741987那麼你的問題是你要加載一個文件dosent存在於指定的位置。 – dburner