Skip to content

Commit 9d342a5

Browse files
committed
scp: remove -d flag
1 parent 8712c99 commit 9d342a5

5 files changed

+13
-16
lines changed

src/Renci.SshNet/ScpClient.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,8 @@ public void Upload(Stream source, string path)
258258
channel.Closed += (sender, e) => input.Dispose();
259259
channel.Open();
260260

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

304-
// Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
305-
// that we expect the target to be a directory.
306-
if (!channel.SendExecRequest($"scp -t -d {_remotePathTransformation.Transform(posixPath.Directory)}"))
303+
// Pass only the directory part of the path to the server.
304+
if (!channel.SendExecRequest($"scp -t {_remotePathTransformation.Transform(posixPath.Directory)}"))
307305
{
308306
throw SecureExecutionRequestRejectedException();
309307
}
@@ -350,9 +348,8 @@ public void Upload(DirectoryInfo directoryInfo, string path)
350348
// start copy with the following options:
351349
// -p preserve modification and access times
352350
// -r copy directories recursively
353-
// -d expect path to be a directory
354351
// -t copy to remote
355-
if (!channel.SendExecRequest($"scp -r -p -d -t {_remotePathTransformation.Transform(path)}"))
352+
if (!channel.SendExecRequest($"scp -r -p -t {_remotePathTransformation.Transform(path)}"))
356353
{
357354
throw SecureExecutionRequestRejectedException();
358355
}

test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_DirectoryInfoAndPath_SendExecRequestReturnsFalse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected override void SetupMocks()
5353
.Setup(p => p.Transform(_path))
5454
.Returns(_transformedPath);
5555
_channelSessionMock.InSequence(sequence)
56-
.Setup(p => p.SendExecRequest(string.Format("scp -r -p -d -t {0}", _transformedPath)))
56+
.Setup(p => p.SendExecRequest(string.Format("scp -r -p -t {0}", _transformedPath)))
5757
.Returns(false);
5858
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
5959
_pipeStreamMock.InSequence(sequence).Setup(p => p.Close());
@@ -92,7 +92,7 @@ public void UploadShouldHaveThrownSshException()
9292
[TestMethod]
9393
public void SendExecREquestOnChannelSessionShouldBeInvokedOnce()
9494
{
95-
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -r -p -d -t {0}", _transformedPath)), Times.Once);
95+
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -r -p -t {0}", _transformedPath)), Times.Once);
9696
}
9797

9898
[TestMethod]

test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override void SetupMocks()
5959
.Setup(p => p.Transform(_remoteDirectory))
6060
.Returns(_transformedPath);
6161
_channelSessionMock.InSequence(sequence)
62-
.Setup(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)))
62+
.Setup(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)))
6363
.Returns(false);
6464
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
6565
_pipeStreamMock.InSequence(sequence).Setup(p => p.Close());
@@ -109,7 +109,7 @@ public void UploadShouldHaveThrownSshException()
109109
[TestMethod]
110110
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
111111
{
112-
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)), Times.Once);
112+
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)), Times.Once);
113113
}
114114

115115
[TestMethod]

test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected override void SetupMocks()
7272
.Setup(p => p.Transform(_remoteDirectory))
7373
.Returns(_transformedPath);
7474
_ = _channelSessionMock.InSequence(sequence)
75-
.Setup(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)))
75+
.Setup(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)))
7676
.Returns(true);
7777
_ = _pipeStreamMock.InSequence(sequence)
7878
.Setup(p => p.ReadByte())
@@ -133,7 +133,7 @@ protected override void Act()
133133
[TestMethod]
134134
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
135135
{
136-
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)), Times.Once);
136+
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)), Times.Once);
137137
}
138138

139139
[TestMethod]

test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_StreamAndPath_SendExecRequestReturnsFalse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected override void SetupMocks()
6363
.Setup(p => p.Transform(_remoteDirectory))
6464
.Returns(_transformedPath);
6565
_ = _channelSessionMock.InSequence(sequence)
66-
.Setup(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)))
66+
.Setup(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)))
6767
.Returns(false);
6868
_ = _channelSessionMock.InSequence(sequence)
6969
.Setup(p => p.Dispose());
@@ -111,7 +111,7 @@ public void UploadShouldHaveThrownSshException()
111111
[TestMethod]
112112
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
113113
{
114-
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t -d {0}", _transformedPath)), Times.Once);
114+
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t {0}", _transformedPath)), Times.Once);
115115
}
116116

117117
[TestMethod]

0 commit comments

Comments
 (0)