perlsshperlnetssh

Net::SFTP::Foreign - rput fails (sort of) if target dir exists


http://metacpan.org/pod/Net::SFTP::Foreign

my ( $user, $password, $host ) = @_;
my ( $source, $dest ) = '/whatever';
my $sftp = Net::SFTP::Foreign->new(
    user     => $user,
    host     => $host,
    password => $password,
    more     => [ -o => 'StrictHostKeyChecking no' ]
);
$sftp->rput(
    $source, $dest,
    overwrite => 1,
    on_error =>
      sub { print $sftp->error; }
);

If $dest exists on $host, rput's on_error always fires and $sftp->error is "Remote directory '/whatever' already exists"

Despite the error, rput carries on and recursively copies the dir, but on the taget host it'll get copied under /whatever, instead of over /whatever. i.e. I end up with /whatever/whatever.

This serves as a crumby workaround if done before the rput, but I don't actually want to remove the destination dir:

$sftp->rremove( $dest );

Anyone have any idea what I'm doing wrong? WOuld I be better of globbing all of the files I want to transfer and then do a foreach $file (@glob_result) { $sftp->put ( yada, yada ) };? That seems inefficient and error prone.


Solution

  • That error is expected, just ignore it.

    Regarding your files being transferred to /whatever/whatever, I am unable to reproduce that problem, at least with the development version of Net::SFTP::Foreign.

    What do you get when you set $Net::SFTP::Foreign::debug = 2|4|64|4096|8192|32768 ?