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
2 个解决方案
#1
有木有大神帮忙啊
#2
A)不同服务器对命令的支持不一样。WebRequestMethods.Ftp.ListDirectory 是
NLST,你还可以试试
ls、
list 命令。
B)返回格式也可能不同,你是否解析错了?
B)返回格式也可能不同,你是否解析错了?
#1
有木有大神帮忙啊
#2
A)不同服务器对命令的支持不一样。WebRequestMethods.Ftp.ListDirectory 是
NLST,你还可以试试
ls、
list 命令。
B)返回格式也可能不同,你是否解析错了?
B)返回格式也可能不同,你是否解析错了?