0

I have a very frustrating situation. I am required to use FTP to retrieve a list, delete, and upload files from some special piece of hardware. All my development is happening on a remote computer that is plugged to the mysterious box. It is to my understanding that the box runs on embedded software. The only way I can FTP to the box is using cmd and calling the ftp.exe, pass the ip and hit enter, enter, meaning there are no credentials. I then can do ls. put and delete. However I need to do a dll that will later be called from a hta/javascript gui and it will be use like this:

var ftp = new ActiveXObject("Mission.FTP")

var list = ftp.ls(hostIP);

but anything I try to do from C# returns the following error:

The remote server returned an error: 202 Command not implemented.

The c# code that is failing is:

FtpWebRequest request = CreateRequest(url, WebRequestMethods.Ftp.ListDirectory);
        using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())

It fails right at the GetResponse() method.

Isn't FTP a standard protocol. Why would the ftp.exe have a different result than the C# way of doing FTP?

Hydrogen-4
  • 187
  • 1
  • 1
  • 15

1 Answers1

1

Enabling network tracing as suggested above I was able to find the exact cause of the problem.

By looking at the log:

System.Net Information: 0 : [9188] FtpControlStream#42866877 - Sending command [PASV]
System.Net.Sockets Verbose: 0 : [9188] Data from Socket#52434070::Send
System.Net.Sockets Verbose: 0 : [9188] 00000000 : 50 41 53 56 0D 0A                               : PASV..
System.Net.Sockets Verbose: 0 : [9188] Exiting Socket#52434070::Send()  -> Int32#6
System.Net.Sockets Verbose: 0 : [9188] Socket#52434070::Receive()
System.Net.Sockets Verbose: 0 : [9188] Data from Socket#52434070::Receive
System.Net.Sockets Verbose: 0 : [9188] 00000000 : 32 30 32 20 43 6F 6D 6D-61 6E 64 20 6E 6F 74 20 : 202 Command not 
System.Net.Sockets Verbose: 0 : [9188] 00000010 : 69 6D 70 6C 65 6D 65 6E-74 65 64 2E 0D 0A       : implemented...
System.Net.Sockets Verbose: 0 : [9188] Exiting Socket#52434070::Receive()   -> Int32#30
System.Net Information: 0 : [9188] FtpControlStream#42866877 - Received response [202 Command not implemented.]
System.Net.Sockets Verbose: 0 : [9188] Socket#52434070::Dispose()
System.Net Information: 0 : [9188] FtpWebRequest#7224250::(Releasing FTP connection#42866877.)
System.Net Error: 0 : [9188] Exception in FtpWebRequest#7224250::GetResponse - The remote server returned an error: 202 Command not implemented.

The solution to the problem was a simple:

request.UsePassive = false;
Hydrogen-4
  • 187
  • 1
  • 1
  • 15