SftpClientTest.CreateDirectory.cs 1.9 KB

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