2012-04-01 4 views
1

다음 스크립트를 사용하여 FTP를 통해 파일을 업로드하려고합니다. 파일은 FTP 서버로 업로드되지만 파일 이름은 항상 이미지라고하며 예외가 없습니다.FTP 파일 업로드 문제 - 누락 된 파일 이름

아마도 내가 놓친 간단한 것이지만 누군가가 도움이 될 수있는 잘못된 부분을 알고 있다면.

public static string _FTPusername = "xx"; 
public static string _FTPPassword = "xxxxx"; 
public static string _FTPServerAddress = "cp.domainname.co.uk"; 
public static string _ftpurl = "ftp://cp.domainname.co.uk/Images"; //= "ftp://cp.domainname.co.uk/Images"; 

try 
{ 
    string filename = Path.GetFileName(source); 
    string ftpfullpath = ConnectionDetails._ftpurl; 
    FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath); 
    ftp.Credentials = new NetworkCredential(ConnectionDetails._FTPusername, ConnectionDetails._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; 
} 
+2

난 당신이 어디서든 파일 이름 변수를 사용하여 표시되지 않는 이유는 무엇입니까? –

답변

0

발견 된 문제 - 간단한 학교 소년 오류였습니다.

public static string _ftpurl = "cp.domainname.co.uk/Images

되어 있어야합니다 :

public static string _ftpurl = "cp.domainname.co.uk

+0

내가 직접 이미지 디렉토리에 FTP를 할 수 있다고했는데? 저에게 당신이 약간 덜 낭비되어 약간의 낭비되는 노력을 덜어 주셨을 것 같습니다. 다행히 결국 오류를 발견했습니다. –

0

문제는이 3 명 선이 될 것 같다 :

string filename = Path.GetFileName(source); 
string ftpfullpath = ConnectionDetails._ftpurl; 
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath); 

당신은 파일 이름 변수를 사용하지 않기 때문에에 전달되는 경로는

ftp://cp.domainname.co.uk/Images

입니다 다음과 같이 시도하십시오.

string ftpfullpath = ConnectionDetails._ftpurl + "/" + filename; 
+0

빠른 답장을 보내 주셔서 감사합니다. 나는 당신이 올바른 영역에 있다고 생각하지만 지금은 "원격 서버가 오류를 반환했습니다 : (550) 파일을 사용할 수 없습니다 (예 : 파일을 찾을 수없고 액세스 할 수 없음)." 그것의 FTP 서버에있는 로컬 파일을 찾는 것 같아 – Steve

+0

ftp 서버에 Images 디렉토리가 있습니까? –

+0

경로가 잘못되었거나 디렉토리에 액세스 할 수 없다고 생각합니다. ftp 클라이언트로 Images 디렉토리에 수동으로 ftp 할 수 있습니까? –