mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 17:25:51 +00:00
cd9ec8f395
This adds an SftpException which sits between the existing SftpPathNotFoundException/ SftpPermissionDeniedException and SshException, and which contains the response code from the SSH_FXP_STATUS packet, along with a default message if one was not provided. SftpPathNotFoundException also gains a Path property which is populated in cases where it makes sense.
66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
|
|
using Renci.SshNet.Common;
|
|
using Renci.SshNet.Sftp;
|
|
|
|
namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
{
|
|
/// <summary>
|
|
/// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
|
|
/// </summary>
|
|
public partial class SftpClientTest : IntegrationTestBase
|
|
{
|
|
[TestMethod]
|
|
[TestCategory("Sftp")]
|
|
public void Test_Sftp_CreateDirectory_In_Current_Location()
|
|
{
|
|
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
|
|
{
|
|
sftp.Connect();
|
|
|
|
sftp.CreateDirectory("test-in-current");
|
|
|
|
sftp.Disconnect();
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory("Sftp")]
|
|
public void Test_Sftp_CreateDirectory_In_Forbidden_Directory()
|
|
{
|
|
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, AdminUser.UserName, AdminUser.Password))
|
|
{
|
|
sftp.Connect();
|
|
|
|
Assert.ThrowsExactly<SftpPermissionDeniedException>(() => sftp.CreateDirectory("/sbin/test"));
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory("Sftp")]
|
|
public void Test_Sftp_CreateDirectory_Invalid_Path()
|
|
{
|
|
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
|
|
{
|
|
sftp.Connect();
|
|
|
|
Assert.ThrowsExactly<SftpPathNotFoundException>(() => sftp.CreateDirectory("/abcdefg/abcefg"));
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory("Sftp")]
|
|
public void Test_Sftp_CreateDirectory_Already_Exists()
|
|
{
|
|
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
|
|
{
|
|
sftp.Connect();
|
|
|
|
sftp.CreateDirectory("test");
|
|
|
|
var ex = Assert.ThrowsExactly<SftpException>(() => sftp.CreateDirectory("test"));
|
|
Assert.AreEqual(StatusCode.Failure, ex.StatusCode);
|
|
}
|
|
}
|
|
}
|
|
}
|