FTPを使用して各ファイル *をダウンロードします *ファイルリストの取得
-
30-10-2019 - |
質問
VB.NETを使用して、リモートFTPサーバーから約100個の非常に小さなファイルを取得する必要があります。当社は、サードパーティのFTPライブラリを購入(またはインストールする)ことを許可しません。したがって、FTPWebRequestのようなものを使用することを余儀なくされています。 (または、すでにVisual Studioの一部であるより良い無料の選択がありますか?)
この方法は機能しますが、非常に遅いです。 (私は絶え間ないログイン/アウトのために想定しています。)
Log in with user name and password. Get a file-list from the remote server. Log out Use that file-list to get each file separtely: Log in, get the file, log out. Log in 99 more times, get each file, log out each time.
代わりに、私たちはおそらくこれを行うべきですが、それは決して機能しません:
Log in with user name and password. ONCE. Get a list of filenames. Download each file. Log out ONCE.
「FTPファイルリストの取得」と「FTPで1つのファイルをダウンロードする方法」のオンラインで数え切れないほどの例が見つかりました...しかし、「各ファイル名を取得して今すぐダウンロードする」ことはありません。
Dim fwr As Net.FtpWebRequest = Net.FtpWebRequest.Create(ftpSite) fwr.Credentials = New NetworkCredential(userName, password) fwr.KeepAlive = True fwr.Method = WebRequestMethods.Ftp.ListDirectory Dim sr As IO.StreamReader = Nothing Try sr = New IO.StreamReader(fwr.GetResponse().GetResponseStream()) Do Until (sr.EndOfStream()) fileName = sr.ReadLine() fwr.Method = WebRequestMethods.Ftp.DownloadFile output = "" Dim sr2 As IO.StreamReader = Nothing Try sr2 = New IO.StreamReader(fwr.GetResponse().GetResponseStream()) output = sr2.ReadToEnd() Catch ex As Exception End Try If (Not sr2 Is Nothing) Then sr2.Close() : sr2 = Nothing Call MsgBox("Got " & fileName & LF & output) Loop Catch ex As Exception End Try If (Not sr Is Nothing) Then sr.Close() : sr = Nothing If (Not fwr Is Nothing) Then fwr = Nothing
正しい解決策はありません
所属していません StackOverflow