Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.3k views
in .NET FTP by
Hi guys, I love your FTP client. I'm using the .Net version in a C# application and think I might have found a bug. Every now and then, when I'm in active mode, the FTP client sends "ORT" to the server when it should send "PORT". I think it happens when the port number chosen by the client is too high. Here are a couple examples:

PORT 151,205,169,246,96,63 (works fine)
ORT 141,157,238,53,19,156 (no good)

I think the problem is in here:

private void SetDataPort(IPEndPoint ep)
{
byte[] hostBytes =BitConverter.GetBytes(ep.Address.Address);
byte[] portBytes = ToByteArray((ushort)ep.Port);

// assemble the PORT command
string cmd = new StringBuilder("PORT ").
Append((short)hostBytes[0]).Append(",").
Append((short)hostBytes[1]).Append(",").
Append((short)hostBytes[2]).Append(",").
Append((short)hostBytes[3]).Append(",").
Append((short)portBytes[0]).Append(",").
Append((short)portBytes[1]).ToString();

// send command and check reply
string reply = SendCommand(cmd);
ValidateReply(reply, "200");

/*
//byte[] hostBytes = ep.Address.GetAddressBytes();

string host = ep.Address.ToString();
System.Console.WriteLine("host="+host);
string byte1=host.Substring(0,host.IndexOf("."));
System.Console.WriteLine("byte1="+byte1);
host=host.Substring(host.IndexOf(".")+1);
System.Console.WriteLine("byte1="+byte1);

string byte2=host.Substring(0,host.IndexOf("."));
host=host.Substring(host.IndexOf(".")+1);
System.Console.WriteLine("byte2="+byte2);

string byte3=host.Substring(0,host.IndexOf("."));
host=host.Substring(host.IndexOf(".")+1);
System.Console.WriteLine("byte3="+byte3);

string byte4=host.Substring(0,host.Length);
System.Console.WriteLine("byte4="+byte4);

byte[] portBytes = ToByteArray((ushort)ep.Port);

string cmd = new StringBuilder("PORT ").
Append(byte1).Append(",").
Append(byte2).Append(",").
Append(byte3).Append(",").
Append(byte4).Append(",").
Append((short)portBytes[0]).Append(",").
Append((short)portBytes[1]).ToString();

// send command and check reply
string reply = SendCommand(cmd);
ValidateReply(reply, "200");
*/
}

6 Answers

0 votes
by
Thanks for pointing this out - we'll take a look. We hope to release a new version soon so we'll try to sort this out before that happens.
0 votes
by
I'm not sure that this problem is caused by a high port anymore because I've not seen this on my ftp server.

[2] Tue 16Mar04 00:12:22 - (000717) ORT 141,157,238,53,19,154
[2] Tue 16Mar04 00:12:22 - (000717) PORT 141,157,238,53,19,155
[2] Tue 16Mar04 00:12:22 - (000717) APPE 004003112004131752ApplicationLog.txt

Anby ideas why this might happen?
0 votes
by
I meant to say that I'm not sure that this is related to a high port number anymore because I now see ORT messages on my FTP server for port numbers lower than other messages where the PORT message is properly constructed. For instance:

[2] Tue 16Mar04 00:12:22 - (000717) ORT 141,157,238,53,19,154
[2] Tue 16Mar04 00:12:22 - (000717) PORT 141,157,238,53,19,155
[2] Tue 16Mar04 00:12:22 - (000717) APPE 004003112004131752ApplicationLog.txt

Thanks for any thoughts on this,

Colin
0 votes
by
This is a weird problem - has anyone else seen this?

Colin, is your FTP server doing any logging? Can you see what it is receiving?


I meant to say that I'm not sure that this is related to a high port number anymore because I now see ORT messages on my FTP server for port numbers lower than other messages where the PORT message is properly constructed. For instance:

[2] Tue 16Mar04 00:12:22 - (000717) ORT 141,157,238,53,19,154
[2] Tue 16Mar04 00:12:22 - (000717) PORT 141,157,238,53,19,155
[2] Tue 16Mar04 00:12:22 - (000717) APPE 004003112004131752ApplicationLog.txt

Thanks for any thoughts on this,

Colin
0 votes
by
This not edtftp's fault. It's always sending the correct PORT command. I'm not completely sure why, but somehow the P is sometimes lost in transit on the way to the FTP server.

The solution to this problem is to just retry the login until it works. I've configured my application to try to login to the ftp server 3 times before giving up and now it works every time.

BTW, I think this is only a problem in active mode since passive mode shouldn't require a port command from the client.

Colin
0 votes
by
I saw problems similar to this when I wrote my own FTP client, usually when going through Nokia or Cisco firewalls (though I suspect it could happen to others). In my case, the outgoing call was a byte off, and the packet-reshaping logic of the firewall dropped the first character.

Is it possible the same is happening to you? I haven't delved into that side of the code much, but it could be related.

-Matt

Categories

...