You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ScpClient: Make -d flag optional or avoid it for better compatibility with Cisco SCP servers #1746
I’m using SSH.NET 2025.1.0 (via NuGet) and ran into the same Cisco SCP issue as described in #829 (“Scp on cisco device not working”).
On Cisco devices, the -d option used by ScpClient for uploads is not supported by their SCP implementation. In #829 this shows up as errors like:
-p -d options not supported
When I look at the 2025.1.0 source for ScpClient, I still see scp -t -d ... being used for uploads.
Example usage:
using var scp = new ScpClient(host, username, password);
scp.RemotePathTransformation = RemotePathTransformation.None;
scp.Connect();
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
scp.Upload(stream, "startup-config");
This works fine with OpenSSH servers but fails against Cisco devices due to the -d flag.
Request / proposal
For better interoperability, it would be helpful if ScpClient:
either removed -d for file uploads and just used
scp -t
or exposed a property to disable -d, e.g.:
public bool UseDirectoryFlag { get; set; } = true;
and then:
var target = _remotePathTransformation.Transform(UseDirectoryFlag ? posixPath.Directory : posixPath.File);
var exec = UseDirectoryFlag
? $"scp -t -d {target}"
: $"scp -t {target}";
if (!channel.SendExecRequest(exec))
{
throw SecureExecutionRequestRejectedException();
}
That would keep current behavior for OpenSSH, but allow users to work with Cisco and other limited SCP implementations without maintaining a custom fork.
Happy to help test any change against Cisco devices if needed.
Since argc includes the program name and SSH.NET passes -t and target, this should always be true. So unless I'm missing something, the -d flag doesn't actually do anything, at least not with the OpenSSH server.
Would be fine with a switch in principle, but given our inability to easily test it (i.e. the failures against OpenSSH), it would probably require some work on your end @MicaelLysen to prove that it works as expected.
Activity
mus65 commentedon Dec 22, 2025
In the
scpimplementation this flag is automatically set ifargc > 2.https://github.com/openssh/openssh-portable/blob/09daf2ac5f248dc5d60a6f3a703b479d67da14b4/scp.c#L667-L668
Since
argcincludes the program name and SSH.NET passes-tandtarget, this should always be true. So unless I'm missing something, the-dflag doesn't actually do anything, at least not with the OpenSSH server.So we might as well remove it? I will open a PR.
mus65 commentedon Dec 22, 2025
I indeed did miss something. 😄
https://github.com/openssh/openssh-portable/blob/09daf2ac5f248dc5d60a6f3a703b479d67da14b4/scp.c#L624
I guess that means
argconly includes the file/directory arguments.There are indeed multiple test failures when we remove
-d, so I guess there must be an opt-in for this. see #1751Rob-Hague commentedon Dec 23, 2025
Would be fine with a switch in principle, but given our inability to easily test it (i.e. the failures against OpenSSH), it would probably require some work on your end @MicaelLysen to prove that it works as expected.
MicaelLysen commentedon Dec 26, 2025
I am definitely able to help out.
I implemented this lazy solution for myself:
This works on our Cisco devices—both routers and switches—across different IOS versions. I’ve tested it on about 10 different devices.
ScpClient: allow disabling the -d flag
ScpClient: allow disabling the -d flag (#1751)