Skip to content
Draft
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
13 changes: 5 additions & 8 deletions src/Renci.SshNet/ScpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ public void Upload(Stream source, string path)
channel.Closed += (sender, e) => input.Dispose();
channel.Open();

// Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
// that we expect the target to be a directory.
if (!channel.SendExecRequest(string.Format("scp -t -d {0}", _remotePathTransformation.Transform(posixPath.Directory))))
// Pass only the directory part of the path to the server.
if (!channel.SendExecRequest(string.Format("scp -t {0}", _remotePathTransformation.Transform(posixPath.Directory))))
{
throw SecureExecutionRequestRejectedException();
}
Expand Down Expand Up @@ -301,9 +300,8 @@ public void Upload(FileInfo fileInfo, string path)
channel.Closed += (sender, e) => input.Dispose();
channel.Open();

// Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
// that we expect the target to be a directory.
if (!channel.SendExecRequest($"scp -t -d {_remotePathTransformation.Transform(posixPath.Directory)}"))
// Pass only the directory part of the path to the server.
if (!channel.SendExecRequest($"scp -t {_remotePathTransformation.Transform(posixPath.Directory)}"))
{
throw SecureExecutionRequestRejectedException();
}
Expand Down Expand Up @@ -350,9 +348,8 @@ public void Upload(DirectoryInfo directoryInfo, string path)
// start copy with the following options:
// -p preserve modification and access times
// -r copy directories recursively
// -d expect path to be a directory
// -t copy to remote
if (!channel.SendExecRequest($"scp -r -p -d -t {_remotePathTransformation.Transform(path)}"))
if (!channel.SendExecRequest($"scp -r -p -t {_remotePathTransformation.Transform(path)}"))
{
throw SecureExecutionRequestRejectedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override void SetupMocks()
.Setup(p => p.Transform(_path))
.Returns(_transformedPath);
_channelSessionMock.InSequence(sequence)
.Setup(p => p.SendExecRequest(string.Format("scp -r -p -d -t {0}", _transformedPath)))
.Setup(p => p.SendExecRequest(string.Format("scp -r -p -t {0}", _transformedPath)))
.Returns(false);
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
_pipeStreamMock.InSequence(sequence).Setup(p => p.Close());
Expand Down Expand Up @@ -92,7 +92,7 @@ public void UploadShouldHaveThrownSshException()
[TestMethod]
public void SendExecREquestOnChannelSessionShouldBeInvokedOnce()
{
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -r -p -d -t {0}", _transformedPath)), Times.Once);
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -r -p -t {0}", _transformedPath)), Times.Once);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void SetupMocks()
.Setup(p => p.Transform(_remoteDirectory))
.Returns(_transformedPath);
_channelSessionMock.InSequence(sequence)
.Setup(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)))
.Setup(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)))
.Returns(false);
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
_pipeStreamMock.InSequence(sequence).Setup(p => p.Close());
Expand Down Expand Up @@ -109,7 +109,7 @@ public void UploadShouldHaveThrownSshException()
[TestMethod]
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
{
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)), Times.Once);
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)), Times.Once);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected override void SetupMocks()
.Setup(p => p.Transform(_remoteDirectory))
.Returns(_transformedPath);
_ = _channelSessionMock.InSequence(sequence)
.Setup(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)))
.Setup(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)))
.Returns(true);
_ = _pipeStreamMock.InSequence(sequence)
.Setup(p => p.ReadByte())
Expand Down Expand Up @@ -133,7 +133,7 @@ protected override void Act()
[TestMethod]
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
{
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)), Times.Once);
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)), Times.Once);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void SetupMocks()
.Setup(p => p.Transform(_remoteDirectory))
.Returns(_transformedPath);
_ = _channelSessionMock.InSequence(sequence)
.Setup(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)))
.Setup(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)))
.Returns(false);
_ = _channelSessionMock.InSequence(sequence)
.Setup(p => p.Dispose());
Expand Down Expand Up @@ -111,7 +111,7 @@ public void UploadShouldHaveThrownSshException()
[TestMethod]
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
{
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)), Times.Once);
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)), Times.Once);
}

[TestMethod]
Expand Down
Loading