SftpClientTest.CreateDirectory.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. [ExpectedException(typeof(SftpPermissionDeniedException))]
  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. sftp.CreateDirectory("/sbin/test");
  30. sftp.Disconnect();
  31. }
  32. }
  33. [TestMethod]
  34. [TestCategory("Sftp")]
  35. [ExpectedException(typeof(SftpPathNotFoundException))]
  36. public void Test_Sftp_CreateDirectory_Invalid_Path()
  37. {
  38. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  39. {
  40. sftp.Connect();
  41. sftp.CreateDirectory("/abcdefg/abcefg");
  42. sftp.Disconnect();
  43. }
  44. }
  45. [TestMethod]
  46. [TestCategory("Sftp")]
  47. [ExpectedException(typeof(SshException))]
  48. public void Test_Sftp_CreateDirectory_Already_Exists()
  49. {
  50. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  51. {
  52. sftp.Connect();
  53. sftp.CreateDirectory("test");
  54. sftp.CreateDirectory("test");
  55. sftp.Disconnect();
  56. }
  57. }
  58. }
  59. }