FTP 서버를 생성하고
클라이언트에서 서버에 로그인해서
파일을 다운로드 받을려고 합니다.
FTP COMMANDS 로 파일 리스트는 클라이언트에서 표시까지 했는데
특정파일을 다운로드 하려고 하면
FTP 응답코드가 550 으로 나오고
"The system cannot find the file specified. " 와 같은 메세지가 나옵니다.
FTP 서버에서 파일을 못 찾아서 나는 응답인가요?
550 응답코드 해설을 찾아보니
"요청된 행위가 일어나지 않았음. 파일은 사용 가능하다." 라고 되어 있던데
영문이랑 좀 안 맞는거 같기도 하고..;;
좋은 소스가 있어도 제대로 쓰지를 못하네요 에효...
.
=============== 어디선가 퍼 온 소스 중 일부====================================
public void Download(string remFileName,string locFileName,Boolean resume)
{
output = new FileStream(locFileName,FileMode.Open);
Socket cSocket = createDataSocket();
long offset = 0;
this.sendCommand("RETR " + remFileName);
if ( this.resultCode != 150 && this.resultCode != 125 )
{
throw new FtpException(this.result.Substring(4));
}
}
private void sendCommand(String command)
{
if ( this.verboseDebugging ) Debug.WriteLine(command,"FtpClient");
Byte[] cmdBytes = Encoding.ASCII.GetBytes( ( command + "\r\n" ).ToCharArray() );
clientSocket.Send( cmdBytes, cmdBytes.Length, 0);
this.readResponse();
}
private void readResponse()
{
this.message = "";
this.result = this.readLine();
if ( this.result.Length > 3 )
this.resultCode = int.Parse( this.result.Substring(0,3) );
else
this.result = null;
}
private Socket createDataSocket()
{
this.sendCommand("PASV");
if ( this.resultCode != 227 ) throw new FtpException(this.result.Substring(4));
int index1 = this.result.IndexOf('(');
int index2 = this.result.IndexOf(')');
string ipData = this.result.Substring(index1+1,index2-index1-1);
int[] parts = new int[6];
int len = ipData.Length;
int partCount = 0;
string buf="";
for (int i = 0; i < len && partCount <= 6; i++)
{
char ch = char.Parse( ipData.Substring(i,1) );
if ( char.IsDigit(ch) )
buf+=ch;
else if (ch != ',')
throw new FtpException("Malformed PASV result: " + result);
if ( ch == ',' || i+1 == len )
{
try
{
parts[partCount++] = int.Parse(buf);
buf = "";
}
catch (Exception ex)
{
throw new FtpException("Malformed PASV result (not supported?): " + this.result, ex);
}
}
}
string ipAddress = parts[0] + "."+ parts[1]+ "." + parts[2] + "." + parts[3];
int port = (parts[4] << 8) + parts[5];
Socket socket = null;
IPEndPoint ep = null;
try
{
socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
ep = new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
socket.Connect(ep);
}
catch(Exception ex)
{
// doubtfull....
if ( socket != null && socket.Connected ) socket.Close();
throw new FtpException("Can't connect to remote server", ex);
}
return socket;
}
첫댓글 혹시 프록시 사용하시나요? 전 프록시 땜에 한번 고생한적이 있습니다. ^^
로컬이 아닌 타 FTP 서버에 접속하니 다운로드 정상적으로 작동하네요 ^^; FTP 설정을 잘못 한 거 같습니다. 아니면 로컬은 안될려나.. '')?