pimp1911 has asked for the wisdom of the Perl Monks concerning the following question:

I am connected already on the remote server(B) via Net::SSH:Expect. I have a series of commands before the below code snippet that tar's up some files for me. I then want to take the tar file and send it back to me on server(A). Will this work within Net::SSH::Expect
#Send files back to Server A my $sftp = $ssh->exec("sftp username\@remote host"); my $pass = $ssh->exec("password"); My debug log tells me at this point tells me that I have a sftp prompt +. But the sftp prompt wont except my next command. my $mput = $ssh->send("mput *.tar")

Replies are listed 'Best First'.
Re: Starting SFTP within Net:SSH::Expect
by atemon (Chaplain) on Aug 31, 2007 at 05:44 UTC

    To send things interactively, you need to wait for the response from the server to make sure that server is ready. Otherwise your command will be send before server is ready and may got ignored. Try the following code.

    #Send files back to Server A my $sftp = $ssh->exec("sftp username\@remote host"); my $pass = $ssh->exec("password"); $ssh->waitfor('ftp>', 2); # Wait 2 seconds to get 'ftp>' prompt. Check + your server's prompt for correct expression. my $mput = $ssh->send("mput *.tar");
    The "waitfor" can take any regular expression and wait for a response matching the expression. For more details check at Net::SSH::Expect

    Cheers !

    --VC



    There are three sides to any argument.....
    your side, my side and the right side.

      VC many many many thanks. I increased the wait for time to 20 seconds. And it worked. Once again thanks.
        One other thing. I changed the code to look for a sftp prompt. $ssh->waitfor('sftp>', 20);