2014-04-06 27 views
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上傳多個文件?

+0

當您將C:\ Programfiles \ Microsoft Visual Studio 8 \ IDE \ dd.jpg粘貼到Windows資源管理器中時,您能看到該文件嗎? – Sefa

+0

@vgSefa,它位於「E:\ Asp.Net Test \ YuvaRK12 \ YuvaRK12 \ Shtri \ dd.jpg」,但它在C:\ Programfiles \ Microsoft Visual Studio 8 \ IDE \ dd.jpg上不可用 – user2741987

+0

@ user2741987那麼你的問題是你要加載一個文件dosent存在於指定的位置。 – dburner

回答

0

你需要使用廣告ftpurl解決文件夾/ file.ext上傳

而且你用簡單的異常必須處理完全相同例外不是一般的。

例如,在您的FTP完整路徑必須是:

@"ftp://ftp.yuvarukhisamaj.com/wwwroot/Shtri/" + filename + ext; 
//ftp://ftp.yuvarukhisamaj.com/wwwroot/Shtri/yourimage.ext; 

該解決您的問題。

這是網絡ftpclass中的一個常見錯誤。

相關問題