Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12400243
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: C#/.net

2014-03-17 21:56:27

    C#试图登录Ftp服务器时,报错“远程服务器返回错误(530)未登录”。

    这是一个什么原因引起的呢?


  1. private void ConnectFTP()
  2. {
  3.         this.ServerUriStr = this.textBox1.Text;
  4.         string UserNameStr = this.textBox2.Text;
  5.         string PasswordStr = this.maskedTextBox1.Text;
  6.         this.ClientUserName = "root";
  7.         this.ClientUserPassword = "";
  8.         /* 使用user和passwd连接ftp服务器 */
  9.         this.ServerUri = new Uri(ServerUriStr);
  10.         this.FtpMainControl = (FtpWebRequest)WebRequest.Create(this.ServerUri);
  11.         this.FtpMainControl.Credentials = new NetworkCredential(this.ClientUserName, this.ClientUserPassword);
  12.         this.FtpMainControl.KeepAlive = true;
  13.         /* 试图从服务器取些文件目录列表下来 */
  14.         this.FtpMainControl.Method = WebRequestMethods.Ftp.ListDirectory;
  15.         WebResponse FtpResponce = this.FtpMainControl.GetResponse();
  16.         StreamReader ListReader = new StreamReader(FtpResponce.GetResponseStream());
  17. }


image

 

而将上面的一句:

  1. this.ClientUserName = "root";

改为

  1. this.ClientUserName = "anonymous";


    这个问题顺利解决了。说明这是一个没有登录成功就获取FTP服务器上的目录而引发的一个异常

    使用root通过命令行登录来验证root+passwd(空)是无法成功登录ftp的

image

阅读(15244) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~