这是代码,请帮忙!我很失落。它成功遍历database.txt中的每个ID,但每次抛出异常并且报告无法下载。在我的智慧结束时,我已经尝试过这么多次改变,但没有。这里的想法是根据日期和用户ID下载文件。
如果找不到 - 捕获异常(如果找到) - 在datagridview中打印。
循环,直到读取了所有ID。
Dim myDate = Format(DateTimePicker2.Value, "yyyyMMdd")
Do Until DateTimePicker2.Value > DateTimePicker3.Value
For Each strID As String In System.IO.File.ReadAllLines("database.txt")
Try
My.Computer.Network.DownloadFile("ftp://user:pass@ftp.ftp.net/" & strID & "/" & myDate & ".txt", My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt")
Catch nullDownload As System.Net.WebException
MsgBox("File " & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt could not be downloaded")
End Try
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt") Then
For Each line As String In
System.IO.File.ReadAllLines(My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt")
DataGridView1.Rows.Add(line.Split(","))
Next
End If
Next
DateTimePicker2.Value = DateTimePicker2.Value.AddDays(1)
Loop
If DateTimePicker2.Value > DateTimePicker3.Value Then
MsgBox("Download complete.")
End If
编辑:只是想澄清一些事情...这无法下载任何事情。即使该文件存在。我可以在我的应用程序中使用单独的函数拉取现有文件,因此我知道它有效并且我知道下载代码有效。这里遗漏的东西......
同样为了清楚起见,文件地址应为ftp://ftp.ftp.net/ID9999/20150718.txt
答案 0 :(得分:0)
好哇!这是约会。通过使用日期作为变量,它失败了。
而不是
My.Computer.Network.DownloadFile("ftp://user:pass@ftp.ftp.net/" & strID & "/" & myDate & ".txt", My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt")
我用
My.Computer.Network.DownloadFile("ftp://user:pass@ftp.ftp.net/" & strID & "/" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt", My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt")