我试图根据使用ListDirectory创建的列表从FTP下载文件,但它没有从读卡器中以可用格式拆分,因此无法使用。我已更新了代码并使其正常工作:
Dim UserName As String
' Sets Username to current logged-in user profile
UserName = Environment.UserName
Dim JobNo As String
JobNo = Textbox1.Text
Dim listRequest As FtpWebRequest = WebRequest.Create("ftp://ftp.site.com/INPUT/" & JobNo & "_*.DBF")
listRequest.Credentials = New System.Net.NetworkCredential(âUsernameâ, âPasswordâ)
listRequest.Method = WebRequestMethods.Ftp.ListDirectory
Dim listResponse As FtpWebResponse = listRequest.GetResponse()
Dim reader As StreamReader = New System.IO.StreamReader(listResponse.GetResponseStream())
Dim Filedata As String = reader.ReadToEnd
Dim directory() As String = Filedata.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
For Each foundFile As String In directory
My.Computer.Network.DownloadFile("ftp://ftp.site.com/INPUT/" & foundFile, "C:\users\â & UserName & â\desktop\temp\" & foundFile, âUsernameâ, âPasswordâ)
Next
更新的部分
Dim reader As StreamReader = New System.IO.StreamReader(listResponse.GetResponseStream())
Dim Filedata As String = reader.ReadToEnd
Dim directory() As String = Filedata.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)