SendCommand results in "502 Bad command or it is not implemented here."

0 votes
asked May 14, 2013 by timorris (120 points)
edited May 16, 2013

We are programming against a proprietary ftp server. One of the commands we need to run is "LS". Typing "LS" in an ftp session results in something different than industry standard. When using Rebex, it results in "502 Bad command or it is not implemented here." I think this is because before issuing my command, Rebex, by itself, sends "FEAT" (Observe log file contents below). Is there any way for me to be in complete control of the commands issued during an ftp session, for example not sending the "FEAT" command?

:: Our 'LS' command returns this:

ftp> LS
200 Port command successful.
150 Opening ASCII mode data connection for transfer
Mailbox ID          St APRF           SNRF           Service Ref. #
CMS                  N EDI_856I       file6jjwgl0015 003577536380496058
CMS                  N EDI_862O       fileZgXSif0016 003577536380763539
226 Transfer Complete.
ftp: 219 bytes received in 0.05Seconds 4.76Kbytes/sec.
ftp>

:: Rebex Log file:

2013-05-14 15:45:00.172 Opening log file.
2013-05-14 15:45:00.203 INFO Ftp(1)[1] Info: Connecting to edi.cat.com:21 using Ftp 4.0.4700.0 (trial version).
2013-05-14 15:45:00.203 INFO Ftp(1)[1] Info: Using proxy none.
2013-05-14 15:45:00.640 DEBUG Ftp(1)[1] Info: Connection succeeded.
2013-05-14 15:45:00.640 INFO Ftp(1)[1] Response: 220 Enterprise FTP server (Version 1.0.0 Nov. 5, 1996)
2013-05-14 15:45:00.656 INFO Ftp(1)[1] Command: USER ESS08F87
2013-05-14 15:45:00.687 INFO Ftp(1)[1] Response: 331 Password required for ESS08F87
2013-05-14 15:45:00.687 INFO Ftp(1)[1] Command: PASS ********
2013-05-14 15:45:00.750 INFO Ftp(1)[1] Response: 230-User logged in, proceed.
2013-05-14 15:45:00.750 INFO Ftp(1)[1] Response:    Current Default Relationship - Recv: ESS08F87 APRF: *BINARY
2013-05-14 15:45:00.750 INFO Ftp(1)[1] Response:    Get option: multiple
2013-05-14 15:45:00.750 INFO Ftp(1)[1] Response: 230 
2013-05-14 15:45:00.750 INFO Ftp(1)[1] Command: FEAT
2013-05-14 15:45:00.796 INFO Ftp(1)[1] Response: 502 Bad command or it is not implemented here.
2013-05-14 15:45:00.796 INFO Ftp(1)[1] Command: LS
2013-05-14 15:45:00.843 INFO Ftp(1)[1] Response: 502 Bad command or it is not implemented here.
2013-05-14 15:45:00.843 INFO Ftp(1)[1] Command: QUIT
2013-05-14 15:45:00.874 INFO Ftp(1)[1] Response: 221 Thanks for using Enterprise.

:: Here is my C# code:

Stream output;
using (Ftp ftp = new Ftp()) {
    ftp.LogWriter = new Rebex.FileLogWriter(@".\_archive\logs\REBEXLog.txt", Rebex.LogLevel.Debug);
    ftp.Connect(Global.DownloadFtpAddress);
    ftp.Login(Global.DownloadUserName, Global.DownloadPassword);
    ftp.SendCommand("ls");
    var resp = ftp.ReadResponse();
    output = new MemoryStream(Encoding.ASCII.GetBytes(resp.Raw));
    ftp.Disconnect();
}

PLEASE HELP!

thanks,

Tim Morris timorris@timorris.com

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered May 15, 2013 by Tomas Knopp (58,890 points)
edited May 16, 2013

There is an option for that.

ftp.Settings.DoNotDetectFeatures = true;

will prevent Rebex FTP client from sending FEAT command:

Stream output;
using (Ftp ftp = new Ftp()) {

    ftp.Settings.DoNotDetectFeatures = true;
    ftp.LogWriter = new Rebex.FileLogWriter(@".\_archive\logs\REBEXLog.txt", Rebex.LogLevel.Debug);
    ftp.Connect(Global.DownloadFtpAddress);
    ftp.Login(Global.DownloadUserName, Global.DownloadPassword);
    ftp.SendCommand("ls");
    var resp = ftp.ReadResponse();
    output = new MemoryStream(Encoding.ASCII.GetBytes(resp.Raw));
    ftp.Disconnect();
}
commented May 15, 2013 by timorris (120 points)
edited May 15, 2013

That solution works in regards to keeping the "FEAT" command from being sent. However, for some reason, I'm still getting "502 Bad command or it is not implemented here." response when I send my "LS" command. Is Rebex interpreting LS and converting it to "DIR" or something behind the scenes? I'm trying to wrap my head around what the difference is between sitting at a console and manually typing "LS" and sending "LS" via Rebex. Manually typing it in, it works, but automating it through Rebex it doesn't work.

commented May 16, 2013 by Tomas Knopp (58,890 points)
edited May 16, 2013

LS is not a command of FTP protocol but command of the ftp commandline utility. 'ls' command does what is equivalent to ftp.GetRawList(); in Rebex Ftp class.

So please try this code to achieve what you want:

        Ftp ftp = new Ftp();
        ftp.Settings.DoNotDetectFeatures = true;
        ftp.Connect("server");
        ftp.Login("user", "password");
        Console.WriteLine(string.Join("\n", ftp.GetRawList()));
        ftp.Disconnect();
...