Telnet and then SSH

Discussion in 'Perl Misc' started by friend.05@gmail.com, Mar 4, 2009.

  1. Guest

    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.
     
    , Mar 4, 2009
    #1
    1. Advertising

  2. Guest

    On Mar 4, 2:47 pm, Ben Morrow <> wrote:
    > Quoth "" <>:
    >
    > > 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

    >
    > It is not easy to transfer files via telnet. Are you sure there's no
    > other way of communicating between these machines?
    >
    > > - 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.??

    >
    > 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.
     
    , Mar 4, 2009
    #2
    1. Advertising

  3. Ben Morrow wrote:
    > Quoth "" <>:
    >> 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');

    >
    > I hope that's not your real password.
    >
    >> $telnet->waitfor('/\$ $/i');
    >>
    >> #From Telnet, SSH to Server 3.
    >>
    >> $scmd = "$ssh = Net::SSH::perl->new($server3)";

    >
    > 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...
     
    Michael Austin, Mar 4, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chandrashekar Tippur

    JAVA API's for ssh and telnet

    Chandrashekar Tippur, Dec 2, 2003, in forum: Java
    Replies:
    2
    Views:
    6,303
    Chandrashekar Tippur
    Dec 4, 2003
  2. Ted
    Replies:
    4
    Views:
    1,221
    Sudsy
    Sep 19, 2004
  3. Jim Isaacson
    Replies:
    5
    Views:
    606
    Default User
    Nov 5, 2004
  4. Replies:
    0
    Views:
    298
  5. Carcarius
    Replies:
    0
    Views:
    299
    Carcarius
    Dec 6, 2007
Loading...

Share This Page