Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

SFTP hangs (winxp)

by rkg (Hermit)
on Nov 09, 2003 at 03:54 UTC ( [id://305631]=perlquestion: print w/replies, xml ) Need Help??

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

Hi

I am trying to use SFTP on a win xp box.

I've loaded Net::SFTP via ppm from http://www.soulcage.net/ppds/.

When I use it, it logs in OK (and it correctly fails if handed an invalid username & password). After logging in, however, it hangs at "Sending SSH2_FXP_INIT"...

Can anyone suggest what I am doing wrong? Thanks.

rkg

Here is the script driving it

use strict; use Data::Dumper; use Net::SFTP; my $sftp = Net::SFTP->new('foo.com', user=>'bar', password=>'baz', debug=>1); $sftp->cd('boop'); $sftp->cd('blap'); $sftp->cd('blaz'); my @files = $sftp->ls; print Dumper(\@files);
And here is the debug output:
denmark: Reading configuration data /.ssh/config denmark: Reading configuration data /etc/ssh_config denmark: Connecting to XXXXXXXX, port 22. denmark: Socket created, turning on blocking... denmark: Remote protocol version 1.99, remote software version OpenSSH +_3.4p1 denmark: Net::SSH::Perl Version 1.23, protocol version 2.0. denmark: No compat match: OpenSSH_3.4p1. denmark: Connection established. denmark: Sent key-exchange init (KEXINIT), wait response. denmark: Algorithms, c->s: 3des-cbc hmac-sha1 none denmark: Algorithms, s->c: 3des-cbc hmac-sha1 none denmark: Entering Diffie-Hellman Group 1 key exchange. denmark: Sent DH public key, waiting for reply. denmark: Received host key, type 'ssh-dss'. denmark: Host 'XXXXXXXX' is known and matches the host key. denmark: Computing shared secret key. denmark: Verifying server signature. denmark: Waiting for NEWKEYS message. denmark: Enabling incoming encryption/MAC/compression. denmark: Send NEWKEYS, enable outgoing encryption/MAC/compression. denmark: Sending request for user-authentication service. denmark: Service accepted: ssh-userauth. denmark: Trying empty user-authentication request. denmark: Authentication methods that can continue: publickey,password, +keyboard-interactive. denmark: Next method to try is publickey. denmark: Next method to try is password. denmark: Trying password authentication. denmark: Login completed, opening dummy shell channel. denmark: channel 0: new [client-session] denmark: Requesting channel_open for channel 0. denmark: channel 0: open confirm rwindow 0 rmax 32768 denmark: Got channel open confirmation, requesting shell. denmark: Requesting service shell on channel 0. denmark: channel 1: new [client-session] denmark: Requesting channel_open for channel 1. denmark: Sending subsystem: sftp denmark: Requesting service subsystem on channel 1. denmark: channel 1: open confirm rwindow 0 rmax 32768 denmark: sftp: Sending SSH2_FXP_INIT
And then it just hangs...

Suggestions? Thanks

Replies are listed 'Best First'.
Re: SFTP hangs (winxp)
by idsfa (Vicar) on Nov 09, 2003 at 05:52 UTC

    First off, I assume that you have tried connecting directly using sftp and verified that the remote server is properly configured to use it? I am especially concerned to see this line in your debug output:

    denmark: Remote protocol version 1.99, ...

    Assuming no problems there, it is helpful to look at the code (this is also helpful). The relevant chunk is:

    buffer_put_char(&msg, SSH2_FXP_INIT); buffer_put_int(&msg, SSH2_FILEXFER_VERSION); send_msg(fd_out, &msg); buffer_clear(&msg); get_msg(fd_in, &msg); /* Expecting a VERSION reply */

    Which indicates that it is hanging while waiting for a version response from the remote machine. Again, I have concerns that the remote machine may not be set up correctly. Do you have debugging info from the server? If you cannot touch it to debug, consider testing sftp connections to your local machine. If those work, you then really have to examine the remote server.


    My parents just came back from a planet where the dominant life form had no
    bilateral symmetry, and all I got was this stupid F-Shirt.
      Yes, I can use sftp (via putty's psftp ) and grab the files manually. I'm using a password, not running pageant.

      I am not sure how to see debug info from the server; as it is a shared box (I am a guest, I don't control it), I suspect I can't.

      I'd rather do this in perl; though if need be, I guess I can use putty batch scrips wrapped in backticks.

      Thanks idsfa for any ideas.........

        Ask the sysadmin of the remote machine if they would be willing to set up a second sshd on another port with logging cranked up so that you can test. It's worth a shot. Otherwise, you need to step through to find the part that is breaking your code.

        Begin at the beginning. First, confirm that you can get Net::SSH::Perl working:

        my $ssh = Net::SSH::Perl->new("host1", protocol=>2, debug=>1); $ssh->login("user1", "pass1"); ($out, $err, $exit) = $ssh->cmd("hostname"); print "Out: $out$/Err: $err$/Exit: $exit$/";

        If that doesn't return the hostname (modulo any syntax errors ... I didn't test the code), then there is something wrong with the server.

        From there, step through the Net::SFTP code until you find the bit that breaks it. (extract follows)

        sub do_init { my $sftp = shift; my $ssh = $sftp->{ssh}; $sftp->debug("Sending SSH2_FXP_INIT"); my $msg = $sftp->new_msg(SSH2_FXP_INIT); $msg->put_int32(SSH2_FILEXFER_VERSION); $sftp->send_msg($msg); $msg = $sftp->get_msg; my $type = $msg->get_int8; if ($type != SSH2_FXP_VERSION) { croak "Invalid packet back from SSH2_FXP_INIT (type $type)"; } my $version = $msg->get_int32; $sftp->debug("Remote version: $version"); ## XXX Check for extensions. } . . . sub send_msg { my $sftp = shift; my($buf) = @_; my $b = Net::SFTP::Buffer->new; $b->put_int32($buf->length); $b->append($buf->bytes); $sftp->{channel}->send_data($b->bytes); }

        Good luck bughunting ...


        My parents just came back from a planet where the dominant life form had no
        bilateral symmetry, and all I got was this stupid F-Shirt.
Re: SFTP hangs (winxp)
by shenme (Priest) on Nov 09, 2003 at 06:00 UTC
    I really wanted to try this out and help, but sheesh!   How did you even get that far?

    My WinXP didn't even have the ssh port 22 defined in \WINNT\SYSTEM32\Drivers\etc\services.   Then I blew up with "Your vendor has not defined Fcntl macro F_SETFL, used at C:/Perl58/site/lib/Net/ SSH/Perl.pm line 214."

    Mine is AS Perl v5.8.0 with Net::SSH::Perl 1.23 from AS and Net::SFTP 0.05 from CPAN.

      Having the exact same problem.
        Has anyone ever gotten this to work in an windows environment?
      Go to control panel and select Security something, and add port 22
        Control Panel -> Security Center -> Windows Firewall -> "Exceptions" tab -> Add Port... -> Name: ******* Port number: 22 TCP OK

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://305631]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-19 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found