forked from robinrodricks/FluentFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetHash.vb
65 lines (52 loc) · 2.04 KB
/
GetHash.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Imports System
Imports System.Net
Imports System.Threading
Imports System.Threading.Tasks
Imports FluentFTP
Namespace Examples
Friend Module GetHashExample
'-----------------------------------------------------------------------------------------
' NOTE! GetChecksum automatically uses the first available hash algorithm on the server,
' And it should be used as far as possible instead of GetHash, GetMD5, GetSHA256...
'-----------------------------------------------------------------------------------------
Sub GetHash()
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest")
conn.Connect()
If conn.HashAlgorithms <> FtpHashAlgorithm.NONE Then
Dim hash As FtpHash
hash = conn.GetHash("/path/to/remote/somefile.ext")
If hash.Verify("/path/to/local/somefile.ext") Then
Console.WriteLine("The computed hashes match!")
End If
If conn.HashAlgorithms.HasFlag(FtpHashAlgorithm.MD5) Then
conn.SetHashAlgorithm(FtpHashAlgorithm.MD5)
hash = conn.GetHash("/path/to/remote/somefile.ext")
If hash.Verify("/path/to/local/somefile.ext") Then
Console.WriteLine("The computed hashes match!")
End If
End If
End If
End Using
End Sub
Async Function GetHashAsync() As Task
Dim token = New CancellationToken()
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest")
Await conn.ConnectAsync(token)
If conn.HashAlgorithms <> FtpHashAlgorithm.NONE Then
Dim hash As FtpHash
hash = Await conn.GetHashAsync("/path/to/remote/somefile.ext", token)
If hash.Verify("/path/to/local/somefile.ext") Then
Console.WriteLine("The computed hashes match!")
End If
If conn.HashAlgorithms.HasFlag(FtpHashAlgorithm.MD5) Then
conn.SetHashAlgorithm(FtpHashAlgorithm.MD5)
hash = Await conn.GetHashAsync("/path/to/remote/somefile.ext", token)
If hash.Verify("/path/to/local/somefile.ext") Then
Console.WriteLine("The computed hashes match!")
End If
End If
End If
End Using
End Function
End Module
End Namespace