Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: SFTP on Windows

by syphilis (Archbishop)
on Nov 01, 2010 at 01:21 UTC ( [id://868666]=note: print w/replies, xml ) Need Help??


in reply to SFTP on Windows

I use Net::SSH2 to handle both sftp and scp.
As regards coding, it's much simpler to do the transfer via scp:
$ret = $ssh2->scp_put($local, $remote);
In order to sftp, one first has to write the code that's going to open the file on the remote server, read the local file into a buffer, then transmit the local file (one buffer at a time) to the remote server.

I would expect that if the server you're connecting to can handle sftp, then it can also handle scp - and I therefore recommend using scp.
However, if you've already written the sub that handles the sftp, then there's no reason to not keep using it.

I've found it necessary (over slow connections) to patch SSH2.pm as follows, in order for scp to work correctly. (This patch is already included in the ppm packages from the uwinnipeg repo.):
--- SSH2.pm_orig Mon Aug 23 20:06:32 2010 +++ SSH2.pm Mon Aug 23 20:36:30 2010 @@ -373,8 +373,18 @@ $self->error(0, "want $block, have $count"), return unless $count == $block; die 'sysread mismatch' unless length $buf == $count; - $self->error(0, "error writing $count bytes to channel"), retur +n - unless $chan->write($buf) == $count; + my $wrote = 0; + while ($wrote >= 0 && $wrote < $count) { + my $wr = $chan->write($buf); + last if $wr < 0; + $wrote += $wr; + $buf = substr $buf, $wr; + } + unless($wrote == $count) { + my @error = $self->error(); + warn "Error writing $count bytes to channel: @error\n"; + return; + } } # send/receive SCP acknowledgement
See the discussion about that bug for further details.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: SFTP on Windows
by Limbic~Region (Chancellor) on Nov 01, 2010 at 13:17 UTC
    syphilis,
    As I indicated, I was able to kludge together a solution using Net::SSH2. There are a couple of reasons why I specifically wanted SFTP. The first is because sometimes that is all that is available (see derby's reply elsewhere in the thread). The second is because SFTP allows you to do things like look around before deciding what to do where you have to know what you want with SCP. I am not saying this is unacceptable but after searching a bit, I was suprised there wasn't a very simple straight forward solution.

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found