Retrieves a checksum of the given file using a checksumming method
that the server supports, if any. The algorithm used goes in this order:
1. HASH command; server preferred algorithm. See FtpClient.SetHashAlgorithm()
2. MD5 / XMD5 commands
3. XSHA1 command
4. XSHA256 command
5. XSHA512 command
6. XCRC command
Namespace: System.Net.FtpClient.Extensions
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461
Syntax
C# |
---|
public static FtpHash GetChecksum(
this FtpClient client,
string path
) |
Visual Basic |
---|
<ExtensionAttribute>
Public Shared Function GetChecksum (
client As FtpClient,
path As String
) As FtpHash |
Visual C++ |
---|
public:
[ExtensionAttribute]
static FtpHash^ GetChecksum(
FtpClient^ client,
String^ path
) |
Return Value
Type:
FtpHashFtpHash object containing the value and algorithm. Use the IsValid property to
determine if this command was successfull. FtpCommandException's can be thrown from
the underlying calls.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
FtpClient. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
Examples
C# |
Copy
|
using System;
using System.Net;
using System.Net.FtpClient;
using System.Net.FtpClient.Extensions;
namespace Examples {
public static class GetChecksumExample {
public static void GetChceksumExample() {
FtpHash hash = null;
using (FtpClient cl = new FtpClient()) {
cl.Credentials = new NetworkCredential("user", "pass");
cl.Host = "some.ftpserver.on.the.internet.com";
hash = cl.GetChecksum("/path/to/remote/file");
if (hash.IsValid && hash.Algorithm != FtpHashAlgorithm.CRC) {
if (hash.Verify("/some/local/file")) {
Console.WriteLine("The checksum's match!");
}
}
}
}
}
}
|
See Also