-
-
Notifications
You must be signed in to change notification settings - Fork 657
/
Copy pathGetChecksum.cs
51 lines (40 loc) · 1.46 KB
/
GetChecksum.cs
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
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using FluentFTP;
namespace Examples {
public static class GetChecksumExample {
//-----------------------------------------------------------------------------------------
// 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...
//-----------------------------------------------------------------------------------------
public static void GetChecksum() {
using (var conn = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
conn.Connect();
// Get a hash checksum for the file
FtpHash hash = conn.GetChecksum("/path/to/remote/file");
// Make sure it returned a valid hash object
if (hash.IsValid) {
if (hash.Verify("/some/local/file")) {
Console.WriteLine("The checksum's match!");
}
}
}
}
public static async Task GetChecksumAsync() {
var token = new CancellationToken();
using (var conn = new AsyncFtpClient("127.0.0.1", "ftptest", "ftptest")) {
await conn.Connect(token);
// Get a hash checksum for the file
FtpHash hash = await conn.GetChecksum("/path/to/remote/file", FtpHashAlgorithm.NONE, token);
// Make sure it returned a valid hash object
if (hash.IsValid) {
if (hash.Verify("/some/local/file")) {
Console.WriteLine("The checksum's match!");
}
}
}
}
}
}