Bonjour,
j'utilise ce code pour faire un upload et download de fichier sur un serveur FTP securisé:
download :
er upload
Code : 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
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 Public Function downloadFTP(ByVal Cheminfile As String, ByVal URL As String, ByVal bk As String, ByVal pw As String, ByVal Er As String) As String Form1.ProgressBar1.Value = 0 Dim requ As FtpWebRequest = Nothing Dim resp As FtpWebResponse = Nothing Dim respStrm As Stream = Nothing Dim fileStrm As FileStream = Nothing Dim filename As String Try requ = CType(WebRequest.Create(URL), FtpWebRequest) Application.DoEvents() requ.Credentials = New NetworkCredential(bk, pw) requ.Method = WebRequestMethods.Ftp.DownloadFile resp = CType(requ.GetResponse(), FtpWebResponse) respStrm = resp.GetResponseStream() filename = Path.GetFileName(requ.RequestUri.LocalPath) fileStrm = File.Create(Cheminfile & "\" & filename) Dim buff(1024) As Byte Dim bytesread As Integer = 0 While (True) bytesread = respStrm.Read(buff, 0, buff.Length) Form1.ProgressBar1.Maximum = 100 Form1.ProgressBar1.Value += 20 If (bytesread = 0) Then Exit While fileStrm.Write(buff, 0, bytesread) End While Er = "Download de " Catch ex As UriFormatException Er = ex.Message Catch ex As WebException Er = ex.Message Catch ex As IOException Er = ex.Message Finally If respStrm IsNot Nothing Then respStrm.Close() If fileStrm IsNot Nothing Then fileStrm.Close() End Try Return Er End Function
je voudrais mettre un progressbar pour voir la progression mais je galère, je travail sur le while et rien n'a faire je n'arrive pas a coder la barre...
Code : 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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 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 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 requStrm = requ.GetRequestStream() Dim buff(2048) As Byte Dim bytesRead As Integer = 0 fileStrm = File.OpenRead(filename) Do While (True) bytesRead = fileStrm.Read(buff, 0, buff.Length) If (bytesRead = 0) Then Exit Do requStrm.Write(buff, 0, bytesRead) Loop requStrm.Close() resp = CType(requ.GetResponse(), FtpWebResponse) Er = "Upload de " 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
pouvez-vous m'aider merci![]()
Partager