从FTP站点下载所有文件 [英] Download all files from FTP site
本文介绍了从FTP站点下载所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
有任何链接可以指导我如何从FTP站点文件夹中获取所有文件并将其下载到我的本地文件夹?
编辑:
我有一个下载文件的代码。不是每个文件都在上面。感谢是否有人可以修改我的代码以满足下载所有文件。
Hi all,
Got any link for guide me how to get all files from an FTP site folder and download it to my local folder?
I have a code to download a file. Not every file on it. Appreciate if someone can mod my code to meet the download all file.
Private Sub Download(ByVal strNewImgPath As String)
Dim reqFTP As FtpWebRequest = Nothing
Dim ftpStream As Stream = Nothing
Try
Dim outputStream As New FileStream(strNewImgPath, FileMode.Create)
reqFTP = DirectCast(FtpWebRequest.Create(New Uri(strImgFTPSitePath)), FtpWebRequest)
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
reqFTP.UseBinary = True
reqFTP.Credentials = New NetworkCredential(strFTPUsername, strFTPPassword)
Dim response As FtpWebResponse = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
ftpStream = response.GetResponseStream()
Dim cl As Long = response.ContentLength
Dim bufferSize As Integer = 2048
Dim readCount As Integer
Dim buffer As Byte() = New Byte(bufferSize - 1) {}
readCount = ftpStream.Read(buffer, 0, bufferSize)
While readCount > 0
outputStream.Write(buffer, 0, readCount)
readCount = ftpStream.Read(buffer, 0, bufferSize)
End While
ftpStream.Close()
outputStream.Close()
response.Close()
Catch ex As Exception
If ftpStream IsNot Nothing Then
ftpStream.Close()
ftpStream.Dispose()
End If
Throw New Exception(ex.Message.ToString())
End Try
End Sub
推荐答案
这篇关于从FTP站点下载所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文