1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
Public Function uploadFTP(ByVal filename As String, ByVal URL As String, ByVal bk As String, ByVal pw As String, ByRef Er As String) As String
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim requStrm As Stream = Nothing
Dim fileStrm As FileStream = Nothing
Try
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim requStrm As Stream = Nothing
Dim fileStrm As FileStream = Nothing
Try
requ = CType(WebRequest.Create(URL), FtpWebRequest)
requ.Credentials = New NetworkCredential(bk, pw)
requ.Method = WebRequestMethods.Ftp.UploadFile
requ.Timeout = System.Threading.Timeout.Infinite
requ.Proxy = Nothing
Dim requStrm As Stream = requ.GetRequestStream()
Dim fs As New FileStream(tmpfi, FileMode.Open)
Dim bytesRead As Integer = 0
Dim bytesSoFar As Long = 0
Dim buffer4 As Byte() = New Byte(2048) {}
While (MisMatchData(bytesRead, fs.Read(buffer4, 0, buffer4.Length))) <> 0
bytesSoFar += bytesRead
requStrm.Write(buffer4, 0, bytesRead)
Bgw.ReportProgress((bytesSoFar * 100) / fi.Length, "Uploading file : ...")
End While
fs.Close()
resp = CType(requ.GetResponse(), FtpWebResponse)
Catch ex As UriFormatException
Er = ex.Message
Catch ex As IOException
Er = ex.Message
Catch ex As WebException
Er = ex.Message
Finally
If resp IsNot Nothing Then resp.Close()
If fileStrm IsNot Nothing Then fileStrm.Close()
If requStrm IsNot Nothing Then requStrm.Close()
End Try
Return Er
End Function
Public Function MisMatchData(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
Private Sub Bgw_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles Bgw.ProgressChanged
If Not e.progresspercentage > 100
Me.ProgressBar1.Value = e.ProgressPercentage
Me.text = e.userstate.tostring
End If
End Sub |
Partager