Share

.NET FTP Client

Tracker: Bugs

5 226 response not received from some ftp servers - ID: 1560909
Last Update: Comment added ( energed )

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();


Nobody/Anonymous ( nobody ) - 2006-09-18 17:29

5

Open

None

Nobody/Anonymous

Interface (example)

None

Public


Comments ( 2 )




Date: 2008-09-23 15:38
Sender: energed

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);
}


Date: 2006-10-10 00:43
Sender: xraytux

Logged In: YES
user_id=1218689

This fix works for me too.


Log in to comment.

Attached File

No Files Currently Attached

Change

No changes have been made to this artifact.