mariog has asked for the wisdom of the Perl Monks concerning the following question:
Hello
I do not manage to copy the files on a remote sftp dir then once the file is copied and only if the copy is successful delete the file.
I have tried with net:sftp::foreign rget and get methods but they always complain that my localdir is a directory
thanks#! /usr/bin/env perl use strict; use warnings; use feature qw(say); use autodie; use Net::SFTP::Foreign; use constant { HOST => "sftp.mariog.net", REMOTE_DIR => "/Daily", LOCAL_DIR => "/root", USER_NAME => "MGO", PASSWORD => "mypass", DEBUG => "0", }; my $sftp; $sftp = Net::SFTP::Foreign->new ( HOST, timeout => 240, user => USER_NAME, password => PASSWORD, autodie => 1, ); # # Fetch Files # $sftp->setcwd( REMOTE_DIR ); my @files = @{ $sftp->ls }; #Returns a reference to an array of hashe +s for my $file ( @files ) { $sftp->get($file->{filename}, LOCAL_DIR) or die "file transfer failed: " . $sftp->error; $sftp->remove( $file->{filename} ); } $sftp->disconnect;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: copy files on sftp to local dir and delete copied file
by choroba (Cardinal) on Sep 24, 2015 at 11:26 UTC | |
by salva (Canon) on Sep 24, 2015 at 12:02 UTC | |
by mariog (Acolyte) on Sep 24, 2015 at 13:13 UTC | |
by MidLifeXis (Monsignor) on Sep 24, 2015 at 13:22 UTC | |
|
Re: copy files on sftp to local dir and delete copied file
by Anonymous Monk on Sep 25, 2015 at 00:25 UTC | |
by u65 (Chaplain) on Sep 25, 2015 at 10:48 UTC |