0

Aright, so here's how it goes I'm trying to set a up a polling system to pull log files from several laser systems each with their own ftp. However, I'm running into difficulty when attempting to call the FtpWebResponse call to download the log file the following is the code I'm using:

// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://192.168.10.140/param.dat");
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential("user", "pass");
request.UsePassive = false;
request.Proxy = null;
request.UseBinary = true;

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

So I freeze up on that last line with: "The remote server returned an error: (502) Command not implemented."

I've a few different ways to grab files from the system just to see if it's some kind of setting I'm missing this is my results:

  • Microsoft CMD.exe: Connects up fine and can download files and perform standard ftp commands
  • Internet Explorer: Entering in address to file it downloads the file just fine
  • Firefox: "The remote server returned an error: (502) Command not implemented."
  • Chrome: "Error 606 (net::ERR_FTP_COMMAND_NOT_SUPPORTED): Unknown error."

Now there's not a lot of information I can get on the actual ftp set-up on the laser systems due to a long story I wont get into here but from what I'm seeing perhaps it uses some kind of legacy protocol that IE and CMD support or I'm missing something obvious. I've attempted flipping around the FtpWebRequest setting but nothing seems to work. I would really love to use this solution and not have the program auto build ftp batch files as it would really just make be sad as having everything run in program would be so much more elegant and easier to work with. Any ideas folks?

Levi Jordan
  • 13
  • 1
  • 1
  • 4
  • Levi, have you looked at any of the `MSDN` examples on line..? here is a link you can checkout to get some clues/ideas [FtpWebResponse](http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.getresponse.aspx) – MethodMan Jun 25 '13 at 20:30
  • Thanks for the link but I think I've setup the general calls correctly for a download based on the other examples, the next step after getting the response to initialize is to pass it into a streamreader and pull the data out that way but I need a positive response first. I seem to be connecting up to the ftp; as looking at the webexception that is thrown on crash I can see that the banner message in response is correct "220 Excimer Controller FTP Server ready"(Same I get connecting through CMD.exe). – Levi Jordan Jun 25 '13 at 20:49

1 Answers1

0

One of the things that could be causing your 502 error is attempting to use active mode when it is disabled on the server. Try using passive mode:

request.UsePassive = true

Also, from the documentation:

The URI may be relative or absolute. If the URI is of the form "ftp://contoso.com/%2fpath" (%2f is an escaped '/'), then the URI is absolute, and the current directory is /path. If, however, the URI is of the form "ftp://contoso.com/path", first the .NET Framework logs into the FTP server (using the user name and password set by the Credentials property), then the current directory is set to /path.

Try changing your URI to an absolute form - it may help avoid the PWD you're seeing.

Geoff
  • 8,551
  • 1
  • 43
  • 50
  • No dice there :( that was the first setting I tried. I was under the impression that windows CMD.exe defaults to active and it can connect fine. (But yes I did try setting passive mode but no change at all in error code) – Levi Jordan Jun 25 '13 at 20:53
  • Makes sense. So have you tried debugging the actual traffic, for example using Wireshark? – Geoff Jun 25 '13 at 21:31
  • Hrm that's interesting ok here is what I get basically using IE ME:Request type I/FTP:Okay/ME:Request: PASV/FTP:502 err/ME:Request type I/FTP:Okay/ME:Request PORT IPinfo/FTP:Okay/ME:Request RETR/FTP:Starts transfer – Levi Jordan Jun 25 '13 at 22:58
  • On the .net I get the following: ME:Request OPTS utf8/FTP:502 err/ME:Request PWD/FTP:502 err/TCP traffic back and forth twice then stops communicating further – Levi Jordan Jun 25 '13 at 23:06
  • So from what it looks like to me the commands from the .Net are getting stuck at the PWD command where as the two implementations that work(IE,CMD.exe) seem to not care about the present working directory. So I guess the question is is there anyway to make .Net trust me that the file path I put into the Uri is correct and work off that...or something :( - PS Chrome and Firefox also fail and stop at a PWD request – Levi Jordan Jun 25 '13 at 23:29
  • Hi Geoff, I tried your URI modification and no such luck. However your continued help has been appreciated and has helped me narrow my searches for things online. Based on this forum discussion http://go4answers.webhost4life.com/Example/ftpwebrequest-disabled-server-157871.aspx I have unfortunately come to the conclusion that it is impossible to not send the PWD request(Even though there is absolutely no need for it?!?) under the current .net version. I will look into some of the 3rd party ftp implementations discussed in that forum post. Thanks for your help but I'm afraid there is no answer. – Levi Jordan Jun 26 '13 at 16:59
  • Ah well - raw socket commands was going to be my next suggestion. I saw some ugly CMD-launch suggestions too, but not something I personally would use. Good luck! – Geoff Jun 26 '13 at 19:25