WebRequestMethods.Ftp.ListDirectory 找不到文件夹

itisapity 2015-05-05 06:50:14
使用ListDirectory 只能找到FTP上的文件,就是发现不了文件夹。但是用FileZilla 都可以看到。求大神指教,代码如下:

Dim FTP As FtpWebRequest
Dim Response As FtpWebResponse
Dim lsContent As List(Of String) = New List(Of String)
Dim strContent As String = String.Empty
Try
FTP = FtpWebRequest.Create(New Uri(FTP_FilePath))
FTP.UseBinary = True
FTP.KeepAlive = False
FTP.Method = WebRequestMethods.Ftp.ListDirectory

FTP.Credentials = New NetworkCredential(userName, userPwd)
Response = FTP.GetResponse

Dim content(1024) As Byte
Dim index_a As Integer = 0
Dim bufferLen As Integer = 0
index_a = Response.GetResponseStream.Read(content, 0, content.Length)
bufferLen = bufferLen + index_a

While index_a > 0
index_a = Response.GetResponseStream.Read(content, 0, content.Length)
bufferLen = bufferLen + index_a
End While

strContent = strContent & System.Text.Encoding.UTF8.GetString(content, 0, bufferLen)

MsgBox(strContent)



Dim yu As String = strContent.Replace(vbCrLf, "#").Trim
For Each dir As String In yu.Split("#")
If dir.Trim <> "" Then
lsContent.Add(dir)
End If

Next

Catch ex As Exception
errMsg = ex.Message
Finally
If Response IsNot Nothing Then
Response.Close()
End If
End Try


...全文
459 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tiger_Zhao 2015-05-06
  • 打赏
  • 举报
回复
A)不同服务器对命令的支持不一样。WebRequestMethods.Ftp.ListDirectory 是 NLST,你还可以试试 lslist 命令。
B)返回格式也可能不同,你是否解析错了?
itisapity 2015-05-06
  • 打赏
  • 举报
回复
有木有大神帮忙啊

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧