首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

为啥小弟我用FtpWebRequest 实现从FTP上获取文件列表是,提示报错550啊

2012-01-15 
为啥我用FtpWebRequest 实现从FTP上获取文件列表是,提示报错550啊?以下是我写的一段从FTP上获取文件列表的

为啥我用FtpWebRequest 实现从FTP上获取文件列表是,提示报错550啊?
以下是我写的一段从FTP上获取文件列表的代码,当第一次调用的时候能正确获取,但第二次调用的时候就报错550,说远端文件不存在之类的,郁闷几天了,望哪位大侠指引一条明路,不胜感激!!!!!


 'sFtpPath - FTP地址, sFtpUserID - FTP用户名,sFtpPassword - FTP密码, sLoadPath - FTP文件下载到本地的路径,nLen - 文件列表中文件的数量

  '获取文件列表
  Public Function GetFTPFile(ByVal sFtpPath As String, ByVal sFtpUserID As String, ByVal sFtpPassword As String, ByVal sLoadPath As String, ByVal nLen As Integer) As String()

  Dim request As FtpWebRequest
  Dim i As Integer = 0
  Dim FileList(nLen) As String '文件列表

  'On Error GoTo ErrorInformation

  request = WebRequest.Create(sFtpPath)

  request.Method = WebRequestMethods.Ftp.ListDirectory

  request.UseBinary = False

  request.Credentials = New NetworkCredential(sFtpUserID, sFtpPassword)

  Dim response As FtpWebResponse = request.GetResponse

  Dim responseStream As Stream = response.GetResponseStream()
  Dim reader As StreamReader = New StreamReader(responseStream)

  FileList(i) = reader.ReadLine
  While Not IsNothing(FileList(i))
  i = i + 1
  FileList(i) = reader.ReadLine
  End While

  reader.Close()
  response.Close()
  responseStream.Close()

  Return FileList
  Exit Function

ErrorInformation:

  MessageBox.Show("获取文件列表出错:" + Err.Description)
  Exit Function

  End Function

[解决办法]
检查ftp路径,防火墙或者权限
参考
http://www.cnblogs.com/lodestar/archive/2007/04/17/717110.html

热点排行