Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: Help Required - Problem Automating SFTP

by Kraythorne (Sexton)
on Jan 30, 2009 at 11:28 UTC ( [id://740144]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Help Required - Problem Automating SFTP
in thread Help Required - Problem Automating SFTP

Ok, the saga continues...

This is the information I have back from the client:

'We restrict external logins to sftp connections only and chroot the users into their home directories, i.e. you don’t see “/home/mediatech” when you log in, you just see “/”. Now the problem arises when you are chrooted, in this case the command line sftp won’t connect, when you are not chrooted command line sftp works fine. Unfortunately this server is shared with other external customers so it is considered good practice to have all accounts chrooted.

I can’t find anything about why this is the case or how to fix it but I have found that psftp (command line sftp that comes with Putty) works. As far as I can see psftp is a generic command line sftp client that does everything Openssh sftp does. I assume that it would integrate into Perl scripts exactly the same as sftp would.'

So my question is - Can I get Net::SFTP::Foreign to work with Putty psftp? If not is there another module I could use?

Thanks
  • Comment on Re^5: Help Required - Problem Automating SFTP

Replies are listed 'Best First'.
Re^6: Help Required - Problem Automating SFTP
by salva (Canon) on Jan 30, 2009 at 11:52 UTC
    I see, probably what is happening is that they are expecting you to use the old SSH version 1 approach for launching the SFTP server on the remote side.

    Just to test that this is the case, what happens if you run these commands...?

    plink *remoteHost* -p *remotePort* -v sftp-server plink *remoteHost* -p *remotePort* -v /usr/lib/sftp-server
    Does anyone of them hangs (that means that the sftp-server is listening) instead of exiting with an error?

    Once you find how to launch the remote sftp-server, tell Net::SFTP::Foreign to use the same command with the open2_cmd constructor option. For instance:

    my $sftp = Net::SFTP::Foreign->new(open2_cmd => "plink $host -p $port +/usr/lib/sftp-server"); $sftp->error and die "SFTP connection failed: " . $sftp->error;

    update: and BTW, I think the root of the problem is an incomplete chroot'ed configuration for sshd in the remote side. Probably, they have not configured sshd to use internal-sftp server for the SFTP subsystem. Ask them to check that the sshd_config file contains the following line:

    Subsystem sftp internal-sftp
    (a how-to: http://www.debian-administration.org/articles/590)
Re^6: Help Required - Problem Automating SFTP
by Kraythorne (Sexton) on Jan 30, 2009 at 12:30 UTC
    I can get 'plink' to connect and hang up to this point:

    Offered public key
    Offer of public key accepted
    Authenticating with public key "rsa-key-20081029"
    Access granted
    Opened channel for session
    Allocated pty (ospeed 38400bps, ispeed 38400bps
    Started a shell/command

    ..and when I break out of it I get:

    Sent EOF message
    ^C

    So it looks like that works

    However, when I put the same syntax into Net::SFTP::Foreign, after the shell starts, I get:

    Server exited on signal "INT"
    Disconnected: All channels closed

    Are we getting closer?
      Post here the full plink command you are using.

      Also, set...

      $Net::SFTP::Foreign::debug = -1;
      in your script, before the constructor call, and post here the output you get.
Re^6: Help Required - Problem Automating SFTP
by Kraythorne (Sexton) on Jan 30, 2009 at 13:17 UTC
    Command Line 'Plink':

    C:\Program Files\PuTTY>plink *mycompany@host* -P *port* -v -i c:/id_cmf_mediatech.ppk sftp-server
    Looking up host "*host_IP*"
    Connecting to *host_IP* port *port*
    Server version: SSH-2.0-OpenSSH_5.1
    We claim version: SSH-2.0-PuTTY_Release_0.60
    Using SSH protocol version 2
    Doing Diffie-Hellman group exchange
    Doing Diffie-Hellman key exchange with hash SHA-256
    Host key fingerprint is:
    ssh-rsa 2048 *FINGERPRINT*
    Initialised AES-256 SDCTR client->server encryption
    Initialised HMAC-SHA1 client->server MAC algorithm
    Initialised AES-256 SDCTR server->client encryption
    Initialised HMAC-SHA1 server->client MAC algorithm
    Reading private key file "c:/id_cmf_mediatech.ppk"
    Using username "mediatech".
    Offered public key
    Offer of public key accepted
    Authenticating with public key "rsa-key-20081029"
    Access granted
    Opened channel for session
    Started a shell/command

    *HANGS HERE UNTIL I BREAK*

    Sent EOF message
    ^C


    Net::SFTP::Foreign code:

    #228 ssh cmd: "c:/program files/putty/plink" *mycompany*@*host* -P *port* -v -i c:\id_cmf_mediatech.ppk sftp-server
    #228 queueing msg len: 5, code:1, id:3 ... 1 00 00 00 05 01 00 00 00 03 | .........
    #228 waiting for message... 1
    Looking up host "*host_IP*"
    Connecting to *host_IP* port *port*
    Server version: SSH-2.0-OpenSSH_5.1
    We claim version: SSH-2.0-PuTTY_Release_0.60
    Using SSH protocol version 2
    Doing Diffie-Hellman group exchange
    Doing Diffie-Hellman key exchange with hash SHA-256
    Host key fingerprint is:
    ssh-rsa 2048 *fingerprint*
    Initialised AES-256 SDCTR client->server encryption
    Initialised HMAC-SHA1 client->server MAC algorithm
    Initialised AES-256 SDCTR server->client encryption
    Initialised HMAC-SHA1 server->client MAC algorithm
    Reading private key file "c:\id_cmf_mediatech.ppk"
    Using username "mediatech".
    Offered public key
    Offer of public key accepted
    Authenticating with public key "rsa-key-20081029"
    Access granted
    Opened channel for session
    Started a shell/command
    #228 got it!, len:95, code:2, id:3, status: - 02 00 00 00 03 00 00 00 18 70 6f 73 69 78 2d 72 65 6e 61 6d 65 40 6f 70 65 6e 73 73 68 2e 63 6f | .........posix-rename@openssh.co 6d 00 00 00 01 31 00 00 00 13 73 74 61 74 76 66 73 40 6f 70 65 6e 73 73 68 2e 63 6f 6d 00 00 00 | m....1....statvfs@openssh.com... 01 32 00 00 00 14 66 73 74 61 74 76 66 73 40 6f 70 65 6e 73 73 68 2e 63 6f 6d 00 00 00 01 32 | .2....fstatvfs@openssh.com....2
    #228 Net::SFTP::Foreign=HASH(0x226e20)->DESTROY called (current pid: 228, discon nect_by_pid: )
    #228 Net::SFTP::Foreign=HASH(0x226e20)->disconnect called (ssh pid: 3028)
    #228 _conn_lost
    #228 _set_status code: 7, str: Connection lost
    #228 _set_err code: 37, str: Connection to remote server is broken
      so, it seems to be working!

      Are you doing anything else in your script, besides calling the constructor?

      Which version of Net::SFTP::Foreign are you using? I am missing some information in the debugging output...

Re^6: Help Required - Problem Automating SFTP
by Kraythorne (Sexton) on Jan 30, 2009 at 13:56 UTC
    Version 1.46

    Yep, just calling the constructor at the mo, I need to get into how the module works a bit more now I know it's working!

    ...a nice bit of code. Thanks!!

    By the way, is there a 'move' method in Net::SFTP::Foreign module so that you can move files from one directory on the FTP site to another?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found