Coding:
Private Sub Download(filePath As String, fileName As String)
Fprogress = True
Dim reqFTP As FtpWebRequest
Progressinc.Value = 0
Dim Kptotal As Double = 0
Try
'filePath = <<The full path where the file is to be created.>>,
'fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
Dim outputStream As New FileStream(Convert.ToString(filePath & Convert.ToString("\")) & fileName, FileMode.Create)
reqFTP = DirectCast(FtpWebRequest.Create(New Uri(Convert.ToString("ftp://" + ftpServerIP + "/") & fileName)), FtpWebRequest)
reqFTP.Timeout = 1000000
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
reqFTP.UseBinary = True
reqFTP.Credentials = New NetworkCredential(ftpUserID, ftpPassword)
Dim response As FtpWebResponse = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
Dim ftpStream As Stream = response.GetResponseStream()
Dim cl As Long = response.ContentLength
Dim bufferSize As Integer = 4097
Dim readCount As Integer
Dim buffer As Byte() = New Byte(bufferSize - 1) {}
''Get file size
Dim Filesize As Long = GetFileSize(fileName)
''
readCount = ftpStream.Read(buffer, 0, bufferSize)
Progressinc.Maximum = Filesize
Dim tempCount = 0
While readCount > 0
Timer1.Enabled = False
lblStatus.Text = "."
Application.DoEvents()
outputStream.Write(buffer, 0, readCount)
lblStatus.Text = ".."
Application.DoEvents()
Kptotal = Kptotal + readCount
Progressinc.Value = Kptotal
lblStatus.Text = "..."
Application.DoEvents()
lblPercentageInc.Text = Format(((Kptotal * 100) / Filesize), "#0.00") & " %"
lblMB.Text = Format(Kptotal / megaByte, "#0.00") & " MB" & " / " & Format(Filesize / megaByte, "#0.00") & " MB"
Application.DoEvents()
lblStatus.Text = "...."
readCount = ftpStream.Read(buffer, 0, bufferSize)
End While
Progressinc.Value = Progressinc.Maximum
ftpStream.Close()
outputStream.Close()
response.Close()
''
Timer1.Enabled = True
lblClose_Click(Nothing, Nothing)
Faild = 0
Catch ex As Exception
Faild = Faild + 1
If DownloadErrorMessage <> ex.Message Then
MessageBox.Show("Network Error! Update Failed!" & vbCrLf & _
"To stop Exe AutoUpdate!" & vbCrLf & _
"(" & ex.Message & ")", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
DownloadErrorMessage = ex.Message
Progressinc.Value = 0
End Try
End Sub
To solve my problem Check 2 things,Step 1: login credentials
Step2 : FilesName is Case Sensitive
** The problem Solved **
0 Comments