Click here to Skip to main content
15,881,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After establishing an SSH connection, when trying to SCP some files from a remote server to another using Renci.SshNet library. The command is working perfectly when given directly to the terminal, but not through .NET

used this in terminal it works perfectly

~$ scp -i /private/key/file  /source/file user@connecting.com:/destination/file


What I have tried:

used this in .NET
SshClient.RunCommand("scp -i /private/key/file  /source/file user@connecting.com:/destination/file");


but this one throwing an error

Permission denied, please try again.
Permission denied, please try again.
user@connecting.com: Permission denied (publickey,password).
lost connection


I used ssh-add to authenticate the keypair automatically and it works fine through the terminal. But I couldn't figure out why it is not working with .NET (used Visual Studio 17.2.1). Please help me to figure this out.
Posted
Updated 31-May-22 19:32pm
v2

1 solution

Consider what SshClient.RunCommand() does. It runs the command string given on the remote system. This is the equivalent of typing
Shell
ssh user@remote scp -i /private/key/file /source/file user@connecting.com:/destinatin file
at the command line.

That's probably not what you're trying to do. What you probably want to look into is ScpClient Class[^] which can be used to copy a file from the local system to the remote system.
 
Share this answer
 
Comments
Arjun P 1-Jun-22 1:46am    
Hi, thank you for your attention,
Actually, I need to SCP from one remote to another. So there is no need to SCP from or to the machine that I'm using. Is there any way I can make it?
The problem is only when I'm passing the command from .NET
k5054 1-Jun-22 9:00am    
It looks like the remote scp command is trying to use password authentication. Are you sure you have the correct path for your /private/key/file, and that its the correct identity file for the remote host?
You could try turning off password authentication by adding -o PasswordAuthentication=false to your command line, You might also try adding -vv (yes, 2 v's) to get debug output to try to see why the remote scp is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900