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

asked 25 Feb '10, 19:24

Anupama's gravatar image

Anupama
2612
accept rate: 0%

edited 26 Feb '10, 12:27

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.2k18

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.

(26 Feb '10, 12:33) Lukas Pokorny ♦♦

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.

link

answered 26 Feb '10, 12:49

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.2k18
accept rate: 32%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×39

Asked: 25 Feb '10, 19:24

Seen: 3,207 times

Last updated: 30 Jul '10, 17:24