Gets the hash of an object on the server using the
currently selected hash algorithm. Supported
algorithms, if any, are available in the HashAlgorithms
property. You should confirm that it's not equal
to FtpHashAlgorithm.NONE before calling this method
otherwise the server trigger a FtpCommandException()
due to a lack of support for the HASH command. You can
set the algorithm using the SetHashAlgorithm() method and
you can query the server for the current hash algorithm
using the GetHashAlgorithm() method.
This feature is experimental and based on the following draft:
http://tools.ietf.org/html/draft-bryan-ftpext-hash-02
Namespace: System.Net.FtpClient
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461
Syntax
C# |
---|
public FtpHash GetHash(
string path
) |
Visual Basic |
---|
Public Function GetHash (
path As String
) As FtpHash |
Visual C++ |
---|
public:
virtual FtpHash^ GetHash(
String^ path
) sealed |
Parameters
- path
- Type: System..::..String
Full or relative path of the object to compute the hash for.
Return Value
Type:
FtpHashThe hash of the file.
Implements
IFtpClient..::..GetHash(String)
Examples
C# |
Copy
|
using System;
using System.Net;
using System.Net.FtpClient;
namespace Examples {
public class GetHashExample {
public static void GetHash() {
using (FtpClient cl = new FtpClient()) {
cl.Credentials = new NetworkCredential("user", "pass");
cl.Host = "some.ftpserver.on.the.internet.com";
if (cl.HashAlgorithms != FtpHashAlgorithm.NONE) {
FtpHash hash;
hash = cl.GetHash("/path/to/remote/somefile.ext");
if (hash.Verify("/path/to/local/somefile.ext")) {
Console.WriteLine("The computed hashes match!");
}
if (cl.HashAlgorithms.HasFlag(FtpHashAlgorithm.MD5)) {
cl.SetHashAlgorithm(FtpHashAlgorithm.MD5);
hash = cl.GetHash("/path/to/remote/somefile.ext");
if (hash.Verify("/path/to/local/somefile.ext")) {
Console.WriteLine("The computed hashes match!");
}
}
}
}
}
}
}
|
See Also