使用ftp c连接服务器时参数或参数中的语法错误501错误# [英] Error 501 syntax error in parameters or arguments when connect server using ftp c#

查看:2246
本文介绍了使用ftp c连接服务器时参数或参数中的语法错误501错误#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



当我编译我的应用程序时,我正在尝试使用ftp c#..连接服务器。有些电脑可以访问,有些则无法访问。那时我得到一个错误:远程服务器返回错误:参数或参数中的501语法错误。

我不明白发生了什么。



请给我一些建议。



非常感谢。





这是我的代码。





Hello everyone.

I'm trying to connect server using ftp c#.. when i compile my app. some computers can access and some other can't. at that time i got an error: " The remote server returned an error: 501 syntax error in parameters or arguments".
I don't understand what are happening.

Give me some advices, please.

Thank you very much.


Here are my code.


public string CheckFTPLogin(string ftpServer, string ftpUserName, string ftpPasssword)
       {
           FtpWebRequest ftpRequest = null;
           WebResponse response = null;
           try
           {
               ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServer + "/"));
               ftpRequest.Credentials = new NetworkCredential(ftpUserName, ftpPasssword);
               ftpRequest.UseBinary = true;
               ftpRequest.Proxy = null;
               ftpRequest.UsePassive = false;
               ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
               response = ftpRequest.GetResponse();
               return "";
           }
           catch (Exception ex)
           {
               return "Error FTP Login Server: " + ex.Message;
           }
           finally
           {
               ftpRequest.Abort();
           }
       }

推荐答案

你将UsePassive设置为false,所以你也需要一些端口打开(在这种情况下,客户端正在监听而不是启动通信)...在某些计算机上,相关端口(21?)可能被防火墙阻止...
You setting UsePassive to false, so you need some port too be open (as in this case the client listening instead of initiating the communication)...It is possible that on some computers the relevant ports (21?) are blocked by the firewall...


这篇关于使用ftp c连接服务器时参数或参数中的语法错误501错误#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆