Error: (502) Command not implemented. Using FtpWebResponse .net

时光毁灭记忆、已成空白 提交于 2019-12-20 07:04:48

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17306890/error-502-command-not-implemented-using-ftpwebresponse-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!