forked from robinrodricks/FluentFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadFileWithProgress.vb
51 lines (42 loc) · 1.4 KB
/
DownloadFileWithProgress.vb
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
Imports System
Imports System.Net
Imports System.Threading
Imports System.Threading.Tasks
Imports FluentFTP
Namespace Examples
Friend Module DownloadFileWithProgressExample
Sub DownloadFile()
Using ftp = New FtpClient("127.0.0.1", "ftptest", "ftptest")
ftp.Connect()
' define the progress tracking callback
Dim progress As Action(Of FtpProgress) =
Sub(ByVal p As FtpProgress)
If p.Progress = 1 Then
' all done!
Else
' percent done = (p.Progress * 100)
End If
End Sub
' download a file with progress tracking
ftp.DownloadFile("D:\Github\FluentFTP\README.md", "/public_html/temp/README.md", FtpLocalExists.Overwrite, FtpVerify.None, progress)
End Using
End Sub
Async Function DownloadFileAsync() As Task
Dim token = New CancellationToken()
Using ftp = New AsyncFtpClient("127.0.0.1", "ftptest", "ftptest")
Await ftp.Connect(token)
' define the progress tracking callback
Dim progress As Progress(Of FtpProgress) = New Progress(Of FtpProgress)(
Sub(p)
If p.Progress = 1 Then
' all done!
Else
' percent done = (p.Progress * 100)
End If
End Sub)
' download a file with progress tracking
Await ftp.DownloadFile("D:\Github\FluentFTP\README.md", "/public_html/temp/README.md", FtpLocalExists.Resume, FtpVerify.None, progress, token)
End Using
End Function
End Module
End Namespace