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
|
Private Sub Buttonupload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonupload.Click
Cursor.Current = Cursors.WaitCursor
For Each(fileName As String in Directory.GetFiles(localPath ,".*.xls",SearchOption.TopDirectoryOnly))
Dim requestFTPUploader As FtpWebRequest = DirectCast(WebRequest.Create(ftpUrl & fileName), FtpWebRequest)
requestFTPUploader.Credentials = New NetworkCredential(user, password)
requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile
Dim fileInfo As New FileInfo(localPath & fileName)
If Not fileInfo.Exists Then
Cursor.Current = Cursors.Default
MessageBox.Show("Oups " & localPath & fileName & " introuvable", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Cursor.Current = Cursors.WaitCursor
Continue Next
End If
Dim fileStream As FileStream = fileInfo.OpenRead()
Dim bufferLength As Integer = 2048
Dim buffer As Byte() = New Byte(bufferLength - 1) {}
Dim uploadStream As Stream = requestFTPUploader.GetRequestStream()
Dim contentLength As Integer = fileStream.Read(buffer, 0, bufferLength)
While contentLength <> 0
uploadStream.Write(buffer, 0, contentLength)
contentLength = fileStream.Read(buffer, 0, bufferLength)
End While
uploadStream.Close()
fileStream.Close()
requestFTPUploader = Nothing
Next
Cursor.Current = Cursors.Default
MessageBox.Show("upload fini", _
"Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub |
Partager