C#试图登录Ftp服务器时,报错“远程服务器返回错误(530)未登录”。
这是一个什么原因引起的呢?
- private void ConnectFTP()
- {
- this.ServerUriStr = this.textBox1.Text;
- string UserNameStr = this.textBox2.Text;
- string PasswordStr = this.maskedTextBox1.Text;
- this.ClientUserName = "root";
- this.ClientUserPassword = "";
- /* 使用user和passwd连接ftp服务器 */
- this.ServerUri = new Uri(ServerUriStr);
- this.FtpMainControl = (FtpWebRequest)WebRequest.Create(this.ServerUri);
- this.FtpMainControl.Credentials = new NetworkCredential(this.ClientUserName, this.ClientUserPassword);
- this.FtpMainControl.KeepAlive = true;
- /* 试图从服务器取些文件目录列表下来 */
- this.FtpMainControl.Method = WebRequestMethods.Ftp.ListDirectory;
- WebResponse FtpResponce = this.FtpMainControl.GetResponse();
- StreamReader ListReader = new StreamReader(FtpResponce.GetResponseStream());
- }
而将上面的一句:
- this.ClientUserName = "root";
改为
- this.ClientUserName = "anonymous";
这个问题顺利解决了。说明这是一个没有登录成功就获取FTP服务器上的目录而引发的一个异常。
使用root通过命令行登录来验证root+passwd(空)是无法成功登录ftp的

