From 9d342a59174e387ac62c362cc5f7953ee935229e Mon Sep 17 00:00:00 2001 From: Marius Thesing Date: Mon, 22 Dec 2025 17:22:01 +0100 Subject: [PATCH] scp: remove -d flag --- src/Renci.SshNet/ScpClient.cs | 13 +++++-------- ...ectoryInfoAndPath_SendExecRequestReturnsFalse.cs | 4 ++-- ...d_FileInfoAndPath_SendExecRequestReturnsFalse.cs | 4 ++-- .../ScpClientTest_Upload_FileInfoAndPath_Success.cs | 4 ++-- ...oad_StreamAndPath_SendExecRequestReturnsFalse.cs | 4 ++-- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Renci.SshNet/ScpClient.cs b/src/Renci.SshNet/ScpClient.cs index 90736b99b..6a9631aa5 100644 --- a/src/Renci.SshNet/ScpClient.cs +++ b/src/Renci.SshNet/ScpClient.cs @@ -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(); } @@ -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(); } @@ -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(); } diff --git a/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_DirectoryInfoAndPath_SendExecRequestReturnsFalse.cs b/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_DirectoryInfoAndPath_SendExecRequestReturnsFalse.cs index 68001f51d..10de5f681 100644 --- a/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_DirectoryInfoAndPath_SendExecRequestReturnsFalse.cs +++ b/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_DirectoryInfoAndPath_SendExecRequestReturnsFalse.cs @@ -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()); @@ -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] diff --git a/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs b/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs index 8d677f1fc..b9053ad56 100644 --- a/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs +++ b/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs @@ -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()); @@ -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] diff --git a/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs b/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs index 63610f34d..e514e0e69 100644 --- a/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs +++ b/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs @@ -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()) @@ -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] diff --git a/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_StreamAndPath_SendExecRequestReturnsFalse.cs b/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_StreamAndPath_SendExecRequestReturnsFalse.cs index 2800b88c1..772128bfe 100644 --- a/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_StreamAndPath_SendExecRequestReturnsFalse.cs +++ b/test/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_StreamAndPath_SendExecRequestReturnsFalse.cs @@ -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()); @@ -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]