Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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?

Edit:

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.

VB
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
Posted
Updated 18-Mar-14 18:03pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900