SftpClientTest.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Security.Cryptography;
  2. using Renci.SshNet.Sftp;
  3. namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
  4. {
  5. /// <summary>
  6. /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
  7. /// </summary>
  8. [TestClass]
  9. public partial class SftpClientTest
  10. {
  11. protected static string CalculateMD5(string fileName)
  12. {
  13. using (FileStream file = new FileStream(fileName, FileMode.Open))
  14. {
  15. byte[] hash;
  16. using (var md5 = MD5.Create())
  17. {
  18. hash = md5.ComputeHash(file);
  19. }
  20. file.Close();
  21. StringBuilder sb = new StringBuilder();
  22. for (var i = 0; i < hash.Length; i++)
  23. {
  24. sb.Append(hash[i].ToString("x2"));
  25. }
  26. return sb.ToString();
  27. }
  28. }
  29. private void RemoveAllFiles()
  30. {
  31. using (var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  32. {
  33. client.Connect();
  34. client.RunCommand("rm -rf *");
  35. client.Disconnect();
  36. }
  37. }
  38. /// <summary>
  39. /// Helper class to help with upload and download testing
  40. /// </summary>
  41. private class TestInfo
  42. {
  43. public string RemoteFileName { get; set; }
  44. public string UploadedFileName { get; set; }
  45. public string DownloadedFileName { get; set; }
  46. //public ulong UploadedBytes { get; set; }
  47. //public ulong DownloadedBytes { get; set; }
  48. public FileStream UploadedFile { get; set; }
  49. public FileStream DownloadedFile { get; set; }
  50. public string UploadedHash { get; set; }
  51. public string DownloadedHash { get; set; }
  52. public SftpUploadAsyncResult UploadResult { get; set; }
  53. public SftpDownloadAsyncResult DownloadResult { get; set; }
  54. }
  55. }
  56. }