SftpClientTest.CreateDirectory.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 
  2. using Renci.SshNet.Common;
  3. using Renci.SshNet.Sftp;
  4. namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
  5. {
  6. /// <summary>
  7. /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
  8. /// </summary>
  9. public partial class SftpClientTest : IntegrationTestBase
  10. {
  11. [TestMethod]
  12. [TestCategory("Sftp")]
  13. public void Test_Sftp_CreateDirectory_In_Current_Location()
  14. {
  15. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  16. {
  17. sftp.Connect();
  18. sftp.CreateDirectory("test-in-current");
  19. sftp.Disconnect();
  20. }
  21. }
  22. [TestMethod]
  23. [TestCategory("Sftp")]
  24. public void Test_Sftp_CreateDirectory_In_Forbidden_Directory()
  25. {
  26. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, AdminUser.UserName, AdminUser.Password))
  27. {
  28. sftp.Connect();
  29. Assert.ThrowsExactly<SftpPermissionDeniedException>(() => sftp.CreateDirectory("/sbin/test"));
  30. }
  31. }
  32. [TestMethod]
  33. [TestCategory("Sftp")]
  34. public void Test_Sftp_CreateDirectory_Invalid_Path()
  35. {
  36. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  37. {
  38. sftp.Connect();
  39. Assert.ThrowsExactly<SftpPathNotFoundException>(() => sftp.CreateDirectory("/abcdefg/abcefg"));
  40. }
  41. }
  42. [TestMethod]
  43. [TestCategory("Sftp")]
  44. public void Test_Sftp_CreateDirectory_Already_Exists()
  45. {
  46. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  47. {
  48. sftp.Connect();
  49. sftp.CreateDirectory("test");
  50. var ex = Assert.ThrowsExactly<SftpException>(() => sftp.CreateDirectory("test"));
  51. Assert.AreEqual(StatusCode.Failure, ex.StatusCode);
  52. }
  53. }
  54. }
  55. }