+1 vote
by (130 points)
edited

I am trying to get a file from a Linux box(XXX) which is in private network from another Linux box(YYY) whixh is in public netwrok using Putty generate public private keys. using command:

 ssh.Connect("YYY");
 SshPrivateKey privateKey2 = new SshPrivateKey("abc.ppk", password);
 ssh.Login(username, privateKey2);
 string command= "ssh -N -L 8022:XXX:22 -f YYY";
 string response = ssh.RunCommand(command);

I keep getting the error.

Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
Connecting to localhost...
ssh: connect to host localhost port 8022: Connection refused
Couldn't read packet: Connection reset by peer

Please let me know what is the issue

by (148k points)
Are you able to execute "ssh -N -L 8022:XXX:22 -f YYY" when connected through a terminal? At the moment, it's hard to distinguish which error come from what command or application.

1 Answer

+1 vote
by (148k points)
edited

There is an easier method for retrieving files from a Linux box in a private network - Rebex SFTP component supports tunneling through SSH servers:

using System.Net.Sockets;
using System.Net;
using Rebex.Net;

...

// connect to the Linux box in public network
SshSession session = new SshSession();
session.Connect("YYY");
SshPrivateKey privateKey2 = new SshPrivateKey("abc.ppk", password);
session.Authenticate(username, privateKey2);

// connect to the Linux box in private network
// using a tunnel through the first server
Sftp sftp = new Sftp();
sftp.SetSocketFactory(session.ToSocketFactory()); // sets up tunnelling
sftp.Connect("XXX");
sftp.Login(username, privateKey2); // of course, the credentials can be different here

// get the file using SFTP here
...

Please give this a try, it looks like an easier solution to what you are tryig to do.

...