Menu

#13 226 response not received from some ftp servers

open
nobody
5
2006-09-18
2006-09-18
Anonymous
No

On a DIR command, the code currently expects to either
receive the responses right away or expects to receive
the 226 after the file list is read. However, some ftp
servers don't return the 226 until after the data
channel is closed. In this case, because the data
channel is closed after the message is read, an
erroneous error message about "ftp comment not received
from server" is generated. Moving the following code
in the Dir() method solves the problem:

networkStream = client.GetStream();
fileList = ReadLines(networkStream);
// these two lines were after the message read but
should be here
networkStream.Close();
client.Close();

Discussion

  • xraytux

    xraytux - 2006-10-10

    Logged In: YES
    user_id=1218689

    This fix works for me too.

     
  • Mr. Kimmo P.

    Mr. Kimmo P. - 2008-09-23

    Hi,

    I fixed it by allowing all ok status codes to be accepted as ok in Dir command and others
    Allow status codes 200 - 299 to be ok. I also fixed this part that you write here in same way. Thx.

        public ArrayList Dir\(\)
        \{
            LockTcpClient\(\);
            TcpListener listner = null;
            TcpClient client = null;
            NetworkStream networkStream = null;
            ArrayList tempMessageList = new ArrayList\(\);
            int returnValue = 0;
            string returnValueMessage = "";
            ArrayList fileList = new ArrayList\(\);
    
            SetTransferType\(FTPFileTransferType.ASCII\);
    
            if\(this.mode == FTPMode.Active\)
            \{
                listner = CreateDataListner\(\);
                listner.Start\(\);
            \}
            else
            \{
                client = CreateDataClient\(\);
            \}
    
            tempMessageList = new ArrayList\(\);
            tempMessageList = SendCommand\("NLST"\);
            returnValue = GetMessageReturnValue\(\(string\)tempMessageList\[0\]\);
            if\(\!\(returnValue == 150 || returnValue == 125 || returnValue == 550\)\)
            \{
                throw new Exception\(\(string\)tempMessageList\[0\]\);
            \}
    
            if\(returnValue == 550\) //No files found
            \{
                return fileList;
            \}
    
            if\(this.mode == FTPMode.Active\)
            \{
                client = listner.AcceptTcpClient\(\);
            \}
            networkStream = client.GetStream\(\);
    
            fileList = ReadLines\(networkStream\);
    

    networkStream.Close();
    client.Close();

    if (this.mode == FTPMode.Active) {
    listner.Stop();
    }

            if\(tempMessageList.Count == 1\)
            \{
                tempMessageList = Read\(\);
                returnValue = GetMessageReturnValue\(\(string\)tempMessageList\[0\]\);
                returnValueMessage = \(string\)tempMessageList\[0\];
            \}
            else
            \{
                returnValue = GetMessageReturnValue\(\(string\)tempMessageList\[1\]\);
                returnValueMessage = \(string\)tempMessageList\[1\];
            \}
    
            if\(returnValue < 200 || returnValue > 299\)
            \{
                throw new Exception\(returnValueMessage\);
            \}
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.