Telnet and then SSH

F

friend.05

There are 3 servers.

I am on server 1. I need to get some files from server 3. But I dont
have direct access to server 3. I have to go through Server 2.

- From Server 1 I have to Telnet to Server 2
- From Server 2 I can ftp or ssh to Server 3.


I also don't to whole directory from Server 3. I want to read the file
name and then tranfer only selected files from Server 3 to Server 1.


I want to automate this whole process.

Any suggestion how can I do this.??


One method I was trying was:

Use perl telnet module. And the in telnet command I give SSH command
(using Perl SSH module).

I did ls in ssh command (vis telnet command). But now how will get ls
output to viarable.


Once I have file name which I need then I can scp to server 2. And
from there I can ftp to my local server 1.
 
F

friend.05

It is not easy to transfer files via telnet. Are you sure there's no
other way of communicating between these machines?





Post the code you have, and explain what's going wrong with it.

Ben


From Server 1 I have to Telnet to Server 2 . I can also ftp. So that
won't be problem.


Sample Code: Not sure just trying this one

use Net::Telnet;
use Net::SSH::perl;

#telnet to Server 2

$telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die');
$telnet->open($server2);
$telnet->waitfor('/login: $/i');
$telnet->print('hs767s');
$telnet->waitfor('/password: $/i');
$telnet->print('india512');
$telnet->waitfor('/\$ $/i');

#From Telnet, SSH to Server 3.

$scmd = "$ssh = Net::SSH::perl->new($server3)";
$telnet->print($scmd);
$scmd = "$ssh->login('user', 'pass')";
$telnet->print($scmd);
$scmd = "$ssh->cmd(\"cd /xyz\")";
$telnet->print($scmd);

$scmd = "$ssh->cmd(\"ls\")";
$telnet->print($scmd);

#here what I am trying to do is "ls on Server 3". So I know what
directories are there. Then I want to scp one by one to Server 2.
But how Can I read output of "ls" as I am using SSH-CMD in TELnet cmd.

Once I have it Server 2 then I can ftp to server 1.
 
M

Michael Austin

Ben said:
I hope that's not your real password.


Umm... you seem to be confused here. This string will be sent to
$server2 as a *shell* command, not a Perl statement. If you want you
could run perl on $server2 and pass it statements to execute, but to be
honest it's probably easier just to use ssh(1) on the remote machine.

Ben


I am guessing server2 is a "jump" box that has access to his network AND
the remote (server3) network. And server1 does not have access to the
network server3 is on...

look at ssh tunneling.

From google search:
http://www.revsys.com/writings/quicktips/ssh-tunnel.html
http://www.gb.nrao.edu/pubcomputing/tunnel-howto.shtml

from these you should be able to construct things to do as you need...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top