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");
*/
}