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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)