SftpClientTest.RenameFile.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. RemoveAllFiles();
  33. }
  34. [TestMethod]
  35. [TestCategory("Sftp")]
  36. [Description("Test passing null to RenameFile.")]
  37. [ExpectedException(typeof(ArgumentNullException))]
  38. public void Test_Sftp_RenameFile_Null()
  39. {
  40. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  41. {
  42. sftp.Connect();
  43. sftp.RenameFile(null, null);
  44. sftp.Disconnect();
  45. }
  46. }
  47. }
  48. }