FTP 快速下载许多小文件
Download many small files with FTP quickly
我有一个工作代码可以从 FTP 服务器下载许多文件(数百个),但它非常慢并且经常出现超时错误。
这是我目前的下载方式:
Using ftpClient As New WebClient()
ftpClient.Credentials = New System.Net.NetworkCredential(ftpuser, ftppassword)
For i As Integer = 0 To directoriesDownload.Count - 1
If directoriesDownload(i).Contains(".") Then
If Sync_BackgroundWorker.CancellationPending = True Then
Exit Sub
End If
Dim path As String = "ftp://" & ftpserver & "Datenbank/" + directoriesDownload(i).ToString()
Dim trnsfrpth As String = config.rootpath & "ServerDownload\" + directoriesDownload(i).ToString()
ftpClient.DownloadFile(path, trnsfrpth)
filenametodownload = directoriesDownload(i).ToString()
filesdownloaded += 1
Sync_BackgroundWorker.ReportProgress(filesdownloaded)
End If
Next
ftpClient.Dispose()
End Using
有没有更快的方法从 VB.NET 的 FTP 服务器下载数百个小文件(最大 10 KB)?
如果有选项只登录一次 FTP 而不是每个文件都登录和退出,那将是最好的。
我发现其他人也有同样的问题,但没有有效的结果:
Using FTP to download each file *WHILE* getting the file list
我也尝试过使用 Parallel.For
循环的多线程,但 WebClient
不适用于多线程。如果我尝试 ftpClient.DownloadFileAsync(New Uri(path), trnsfrpth)
.
也是一样
Is there any faster way of downloading hundreds of small files (up to 10 KB) from an FTP server in VB.NET?
...
I also tried multithreading with a Parallel.For
loop, but WebClient
does not work with multithreading. Same thing if I try with ftpClient.DownloadFileAsync(New Uri(path), trnsfrpth).
多线程是必经之路。 WebClient
不支持多线程是不对的。为什么不呢?
如果您在实施多线程 FTP 传输时遇到问题,您应该就此提出问题,而不是就其他(可能不存在的)方式提出问题。
It would be the best if there is an option to sign into the FTP only once instead of logging in and out for every file.
您的代码 仅登录 FTP 一次。
参见 - 关于 FtpWebRequest
的内容同样适用于 WebClient
,因为 WebClient
在内部使用 FtpWebRequest
。
我有一个工作代码可以从 FTP 服务器下载许多文件(数百个),但它非常慢并且经常出现超时错误。
这是我目前的下载方式:
Using ftpClient As New WebClient()
ftpClient.Credentials = New System.Net.NetworkCredential(ftpuser, ftppassword)
For i As Integer = 0 To directoriesDownload.Count - 1
If directoriesDownload(i).Contains(".") Then
If Sync_BackgroundWorker.CancellationPending = True Then
Exit Sub
End If
Dim path As String = "ftp://" & ftpserver & "Datenbank/" + directoriesDownload(i).ToString()
Dim trnsfrpth As String = config.rootpath & "ServerDownload\" + directoriesDownload(i).ToString()
ftpClient.DownloadFile(path, trnsfrpth)
filenametodownload = directoriesDownload(i).ToString()
filesdownloaded += 1
Sync_BackgroundWorker.ReportProgress(filesdownloaded)
End If
Next
ftpClient.Dispose()
End Using
有没有更快的方法从 VB.NET 的 FTP 服务器下载数百个小文件(最大 10 KB)?
如果有选项只登录一次 FTP 而不是每个文件都登录和退出,那将是最好的。
我发现其他人也有同样的问题,但没有有效的结果: Using FTP to download each file *WHILE* getting the file list
我也尝试过使用 Parallel.For
循环的多线程,但 WebClient
不适用于多线程。如果我尝试 ftpClient.DownloadFileAsync(New Uri(path), trnsfrpth)
.
Is there any faster way of downloading hundreds of small files (up to 10 KB) from an FTP server in VB.NET?
...
I also tried multithreading with a
Parallel.For
loop, butWebClient
does not work with multithreading. Same thing if I try with ftpClient.DownloadFileAsync(New Uri(path), trnsfrpth).
多线程是必经之路。 WebClient
不支持多线程是不对的。为什么不呢?
如果您在实施多线程 FTP 传输时遇到问题,您应该就此提出问题,而不是就其他(可能不存在的)方式提出问题。
It would be the best if there is an option to sign into the FTP only once instead of logging in and out for every file.
您的代码 仅登录 FTP 一次。
参见 FtpWebRequest
的内容同样适用于 WebClient
,因为 WebClient
在内部使用 FtpWebRequest
。