Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This is more of the code I am using:# Delete a file on the server: my $success = $sftp->RemoveFile("test.txt"); if ($success != 1) { print $sftp->lastErrorText() . "\n"; exit; } print "Files Deleted!" . "\n";
Thanks for the Help!... # For debugging purposes you can run ssh in verbose mode passing it +the -v option: my $sftp = new Net::SFTP::Foreign(host => $host, user=>$user, passwo +rd=>$pwd, more => '-v'); $sftp->die_on_error("unable to connect to remote host"); $sftp->setcwd('/directory') or die "unable to change cwd: " . $sftp- +>error; print $sftp->cwd . "\n"; my $files = $sftp->ls('/directory', no_wanted => qr/^\./); # get files now $sftp->mget('*.txt', "/in_dir", no_wanted => qr/^\./, numbered => 1) + or die "mget failed: " . $sftp->error; #print "$_->{filename}\n" for @$files; #print "$_->{longname}\n" for @$files; my @all_files; foreach my $files (@$files) { next unless ($files->{filename} =~ m/\.txt$/); push @all_files, $files->{filename}; } if ( !$@ ) { print "\n Transmission complete...\n"; # Delete a file on the server: my $success = $sftp->RemoveFile("test.txt"); if ($success != 1) { print $sftp->lastErrorText() . "\n"; exit; } print "Files Deleted!" . "\n"; }else { print "\n File download failed, try later.\n"; } $sftp->disconnect; do_other_stuff(\@all_files); ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delete files from server after downloading using SFTP
by hbm (Hermit) on Jun 11, 2013 at 21:15 UTC | |
|
Re: Delete files from server after downloading using SFTP
by salva (Canon) on Jun 12, 2013 at 07:50 UTC |