SftpClientTest.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. var hash = MD5.HashData(file);
  16. file.Close();
  17. StringBuilder sb = new StringBuilder();
  18. for (var i = 0; i < hash.Length; i++)
  19. {
  20. sb.Append(hash[i].ToString("x2"));
  21. }
  22. return sb.ToString();
  23. }
  24. }
  25. private void RemoveAllFiles()
  26. {
  27. using (var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  28. {
  29. client.Connect();
  30. client.RunCommand("rm -rf *");
  31. client.Disconnect();
  32. }
  33. }
  34. /// <summary>
  35. /// Helper class to help with upload and download testing
  36. /// </summary>
  37. private class TestInfo
  38. {
  39. public string RemoteFileName { get; set; }
  40. public string UploadedFileName { get; set; }
  41. public string DownloadedFileName { get; set; }
  42. //public ulong UploadedBytes { get; set; }
  43. //public ulong DownloadedBytes { get; set; }
  44. public FileStream UploadedFile { get; set; }
  45. public FileStream DownloadedFile { get; set; }
  46. public string UploadedHash { get; set; }
  47. public string DownloadedHash { get; set; }
  48. public SftpUploadAsyncResult UploadResult { get; set; }
  49. public SftpDownloadAsyncResult DownloadResult { get; set; }
  50. }
  51. }
  52. }