SftpClientTest.RenameFile.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Tests.Common;
  3. using Renci.SshNet.Tests.Properties;
  4. using System;
  5. using System.IO;
  6. namespace Renci.SshNet.Tests.Classes
  7. {
  8. /// <summary>
  9. /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
  10. /// </summary>
  11. public partial class SftpClientTest : TestBase
  12. {
  13. [TestMethod]
  14. [TestCategory("Sftp")]
  15. public void Test_Sftp_Rename_File()
  16. {
  17. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  18. {
  19. sftp.Connect();
  20. string uploadedFileName = Path.GetTempFileName();
  21. string remoteFileName1 = Path.GetRandomFileName();
  22. string remoteFileName2 = Path.GetRandomFileName();
  23. this.CreateTestFile(uploadedFileName, 1);
  24. using (var file = File.OpenRead(uploadedFileName))
  25. {
  26. sftp.UploadFile(file, remoteFileName1);
  27. }
  28. sftp.RenameFile(remoteFileName1, remoteFileName2);
  29. File.Delete(uploadedFileName);
  30. sftp.Disconnect();
  31. }
  32. }
  33. [TestMethod]
  34. [TestCategory("Sftp")]
  35. [Description("Test passing null to RenameFile.")]
  36. [ExpectedException(typeof(ArgumentNullException))]
  37. public void Test_Sftp_RenameFile_Null()
  38. {
  39. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  40. {
  41. sftp.Connect();
  42. sftp.RenameFile(null, null);
  43. sftp.Disconnect();
  44. }
  45. }
  46. }
  47. }