2014-04-06 5 views
0

두 개 이상의 파일을 업로드하려고하지만 연습을위한 단일 fileupload를 시도하고 있지만 예외가 발견되지 않았습니다. 내 작업은 아래와 같습니다.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

FTP를 통해 파일 업로드 프로그램으로 여러 파일을 업로드하려면 어떻게해야합니까?

+0

Windows 탐색기에 C : \ Programfiles \ Microsoft Visual Studio 8 \ IDE \ dd.jpg를 붙여 넣을 때 파일을 볼 수 있습니까? – 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

당신은

은 또한 당신이 정확히 예외하지 일반적으로 하나 처리해야합니다 간단한 예외를 사용하는 업로드 폴더/file.ext를 해결 ftpurl 광고를 사용해야합니다.

예에서 FTP에 대한 전체 경로는 다음과 같아야합니다 : 문제가 해결

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

.

net의 ftpclass에는 일반적인 오류가 있습니다.