SSH to a server and then through that server telnet/FTP to other server

0 votes
asked Jun 25, 2010 by babs (150 points)
edited Apr 23, 2013

Hello, Do you have a suggestion, how can i use rebex to achieve this. We have a one server (Say x ) through which we can access other servers (a,b,c). How can I run a command on server a , and ftp its contents to my machine using rebex dll

regards

1 Answer

+1 vote
answered Jun 28, 2010 by Lukas Pokorny (93,630 points)
edited Apr 23, 2013
 
Best answer

You can use the SshSession class - a part of Rebex.Networking.dll shared library, distributed as a part of all Rebex communication components, including Rebex FTP or Rebex Telnet.

To connect to an FTP or telnet server through an SSH server, use this code:

using Rebex.Net;
...

// connect to SSH server X
SshSession session = new SshSession();
session.Connect("X");
session.Authenticate(userNameForX, passwordForX);

// connect to FTP server A through SSH server X
Ftp ftp = new Ftp();
ftp.SetSocketFactory(session.ToSocketFactory()); // sets up tunneling through SSH
ftp.Connect("A");
ftp.Login(userNameForA, passwordForA);
...

// connect to telnet server B through SSH server X
Telnet telnet = new Telnet("B");
telnet.SetSocketFactory(session.ToSocketFactory()); // sets up tunneling through SSH
// start a Shell 
Shell shell = telnet.StartShell();
...

// connect to SSH server C through SSH server X
Ssh ssh = new Ssh();
ssh.SetSocketFactory(session.ToSocketFactory()); // sets up tunneling through SSH
ssh.Connect("C");
ssh.Login("userNameForC", "passwordForC");
...

A VB.NET sample is available in another forum post.

Other Rebex components (SFTP, IMAP, POP3, SMTP) can also connect over an SSH session in the same way.

commented Aug 17, 2012 by Harris (150 points)
edited Aug 17, 2012

Hi

I logged into a Server "A" using SSH conncetion using your Rebex. Now I need to login to Server "B" from here using SSH hostname username & password VB.net. Can you kindly post the code?

Thanks

commented Aug 17, 2012 by Jan Sotola (16,580 points)
edited Apr 23, 2013

A VB.NET sample is available in another forum post.

...