1

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.

szabgab
  • 6,202
  • 11
  • 50
  • 64
Norma Stitz
  • 89
  • 10

2 Answers2

0

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 ?

salva
  • 9,943
  • 4
  • 29
  • 57
  • Hmm, you're right. I can't reproduce the /whatever/whatever for a simple test program. I'm not sure what I'd done when I observed that behavior. – Norma Stitz Mar 02 '12 at 15:19
  • 1
    Ok, so now my on_error sub checks for that message and ignores it. Other errors will stop my program. Thanks for your reply! – Norma Stitz Mar 02 '12 at 15:27
-1

The source should ./* and the destination ./.

my ( $source, $dest ) = ('/whatever/*','/whatever/');

I hope this works.

user1126070
  • 5,059
  • 1
  • 16
  • 15