Bon apparemment, il faut prendre certaines précautions en VB. Voici un code VB qui marcheJ'ai mis en évidence les différences.
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 Public Function FtpUpload(ByVal uri As Uri, ByVal credentials As NetworkCredential, ByVal fileInfo As FileInfo) As Boolean Dim request As FtpWebRequest = DirectCast(FtpWebRequest.Create(Path.Combine(uri.AbsoluteUri, fileInfo.Name)), FtpWebRequest) request.Method = WebRequestMethods.Ftp.UploadFile request.Credentials = credentials request.UseBinary = True request.KeepAlive = False request.UsePassive = True Dim buffer As Byte() = New Byte(2047) {} Using stream As Stream = request.GetRequestStream() Using fs As FileStream = File.OpenRead(fileInfo.FullName) Dim block As Integer = buffer.Length While (block = fs.Read(buffer, 0, buffer.Length)) stream.Write(buffer, 0, block) End While End Using End Using Return True End Function
A+
Partager