Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support on sftp local changedir mimmicking #590

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ This project was inspired by **Sharp.SSH** library which was ported from java an
* Supports DES-EDE3-CBC, DES-EDE3-CFB, DES-CBC, AES-128-CBC, AES-192-CBC and AES-256-CBC algorithms for private key encryption
* Supports two-factor or higher authentication
* Supports SOCKS4, SOCKS5 and HTTP Proxy
* Sample of sftp client exe
* sftp client can now be configured to always use absolute paths on the server (i.e. changedirectory will keep track of the absolute path and all file actions will provide absolute paths to the server). This gives support for buggy server implementations where changedirectory will use the grown permissions

## Key Exchange Method

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void SetupMocks()
.Setup(p => p.CreateSftpResponseFactory())
.Returns(_sftpResponseFactoryMock.Object);
_serviceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateSftpSession(_sessionMock.Object, -1, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object))
.Setup(p => p.CreateSftpSession(_sessionMock.Object, -1, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object, false))
.Returns(_sftpSessionMock.Object);
_sftpSessionMock.InSequence(sequence)
.Setup(p => p.Connect())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void Arrange()
.Setup(p => p.CreateSftpResponseFactory())
.Returns(_sftpResponseFactoryMock.Object);
_serviceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object))
.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object, false))
.Returns(_sftpSessionMock.Object);
_sftpSessionMock.InSequence(sequence).Setup(p => p.Connect());
_sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
Expand All @@ -74,7 +74,7 @@ public void CreateSftpMessageFactoryOnServiceFactoryShouldBeInvokedOnce()
public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(
p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object),
p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object, false),
Times.Once);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void Arrange()
.Setup(p => p.CreateSftpResponseFactory())
.Returns(_sftpResponseFactoryMock.Object);
_serviceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object))
.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object, false))
.Returns(_sftpSessionMock.Object);
_sftpSessionMock.InSequence(sequence).Setup(p => p.Connect());
_sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
Expand All @@ -71,7 +71,7 @@ public void CreateSftpMessageFactoryOnServiceFactoryShouldBeInvokedOnce()
public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(
p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object),
p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object, false),
Times.Once);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void Arrange()
.Setup(p => p.CreateSftpResponseFactory())
.Returns(_sftpResponseFactoryMock.Object);
_serviceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object))
.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object, false))
.Returns(_sftpSessionMock.Object);
_sftpSessionMock.InSequence(sequence).Setup(p => p.Connect());
_sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
Expand All @@ -75,7 +75,7 @@ public void CreateSftpMessageFactoryOnServiceFactoryShouldBeInvokedOnce()
public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(
p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object),
p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object, false),
Times.Once);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void Arrange()
_sessionMock.Setup(p => p.Connect());
_serviceFactoryMock.Setup(p => p.CreateSftpResponseFactory())
.Returns(_sftpResponseFactoryMock.Object);
_serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object))
_serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding, _sftpResponseFactoryMock.Object, false))
.Returns(_sftpSessionMock.Object);
_sftpSessionMock.Setup(p => p.Connect());

Expand Down
25 changes: 25 additions & 0 deletions src/Renci.SshNet.VS2017.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.NET35", "Renci
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.NETCore", "Renci.SshNet.NETCore\Renci.SshNet.NETCore.csproj", "{8E8229EB-6780-4A8A-B470-E2023FA55AB5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.sftp", "renci.sftp\Renci.sftp.csproj", "{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -103,6 +105,26 @@ Global
{8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x64.Build.0 = Release|Any CPU
{8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x86.ActiveCfg = Release|Any CPU
{8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x86.Build.0 = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|ARM.ActiveCfg = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|ARM.Build.0 = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|x64.ActiveCfg = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|x64.Build.0 = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|x86.ActiveCfg = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Debug|x86.Build.0 = Debug|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|Any CPU.Build.0 = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|ARM.ActiveCfg = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|ARM.Build.0 = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|x64.ActiveCfg = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|x64.Build.0 = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|x86.ActiveCfg = Release|Any CPU
{C0B7112C-064E-4A9A-A22C-7DCBD77FC48B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -111,6 +133,9 @@ Global
{94EE3919-19FA-4D9B-8DA9-249050B15232} = {2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}
{A6C3FFD3-16A5-44D3-8C1F-3613D6DD17D1} = {2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BE1E1CE2-57C9-4766-858E-1DE90D2F51FD}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Renci.SshNet1.vsmdi
EndGlobalSection
Expand Down
3 changes: 2 additions & 1 deletion src/Renci.SshNet/IServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ internal partial interface IServiceFactory
/// <param name="operationTimeout">The number of milliseconds to wait for an operation to complete, or -1 to wait indefinitely.</param>
/// <param name="encoding">The encoding.</param>
/// <param name="sftpMessageFactory">The factory to use for creating SFTP messages.</param>
/// <param name="changeDirIsLocal">If true, the sftp client will always pass absolute paths to serve, and will locally mimmick 'changedir' operations</param>
/// <returns>
/// An <see cref="ISftpSession"/>.
/// </returns>
ISftpSession CreateSftpSession(ISession session, int operationTimeout, Encoding encoding, ISftpResponseFactory sftpMessageFactory);
ISftpSession CreateSftpSession(ISession session, int operationTimeout, Encoding encoding, ISftpResponseFactory sftpMessageFactory, bool changeDirIsLocal);

/// <summary>
/// Create a new <see cref="PipeStream"/>.
Expand Down
5 changes: 3 additions & 2 deletions src/Renci.SshNet/ServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ public ISession CreateSession(ConnectionInfo connectionInfo)
/// <param name="operationTimeout">The number of milliseconds to wait for an operation to complete, or -1 to wait indefinitely.</param>
/// <param name="encoding">The encoding.</param>
/// <param name="sftpMessageFactory">The factory to use for creating SFTP messages.</param>
/// <param name="changeDirIsLocal">If true, the sftp client will always pass absolute paths to serve, and will locally mimmick 'changedir' operations</param>
/// <returns>
/// An <see cref="ISftpSession"/>.
/// </returns>
public ISftpSession CreateSftpSession(ISession session, int operationTimeout, Encoding encoding, ISftpResponseFactory sftpMessageFactory)
public ISftpSession CreateSftpSession(ISession session, int operationTimeout, Encoding encoding, ISftpResponseFactory sftpMessageFactory, bool changeDirIsLocal)
{
return new SftpSession(session, operationTimeout, encoding, sftpMessageFactory);
return new SftpSession(session, operationTimeout, encoding, sftpMessageFactory, changeDirIsLocal);
}

/// <summary>
Expand Down
Loading