GetChecksum.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Net;
  3. using System.Net.FtpClient;
  4. using System.Net.FtpClient.Extensions;
  5. namespace Examples {
  6. public static class GetChecksumExample {
  7. public static void GetChceksumExample() {
  8. FtpHash hash = null;
  9. using (FtpClient cl = new FtpClient()) {
  10. cl.Credentials = new NetworkCredential("user", "pass");
  11. cl.Host = "some.ftpserver.on.the.internet.com";
  12. hash = cl.GetChecksum("/path/to/remote/file");
  13. // Make sure it returned a, to the best of our knowledge, valid
  14. // hash object. The commands for retrieving checksums are
  15. // non-standard extensions to the protocol so we have to
  16. // presume that the response was in a format understood by
  17. // System.Net.FtpClient and parsed correctly.
  18. //
  19. // In addition, there is no built-in support for verifying
  20. // CRC hashes. You will need to write you own or use a
  21. // third-party solution.
  22. if (hash.IsValid && hash.Algorithm != FtpHashAlgorithm.CRC) {
  23. if (hash.Verify("/some/local/file")) {
  24. Console.WriteLine("The checksum's match!");
  25. }
  26. }
  27. }
  28. }
  29. }
  30. }