Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am using perl 5.8.8 and using perl foreign sftp to send a directory of files from one linux server to another. The script will send a list of files to replace files on the target server. The source server has some of the files in the target server but not all. When sending the files over, the target files are being wiped out with a 0 bytes but not replaced with the source file. the target file has had a chmod 777 adjusted to it to allow manipulation. I also don't see an error
#!/usr/bin/perl -I/episys/Perl use lib qw(/episys/Perl/); use Cwd qw(abs_path); use strict; #use warnings; use Net::SFTP::Foreign; use File::Basename; use AppConfig; # read config file my $cfg = new AppConfig; my $pathName = dirname(abs_path($0)); my $configNameWithPath = $pathName . "/res_test_servers.cfg"; $cfg->read($configNameWithPath) or die "Couldn't read config file: $!" +; # Get attributes from config file my $s_list = $cfg->get('server.res_target_servers'); my $inputDir = $cfg->get('source_directory.res_source_directory'); my $outputDir = $cfg->get('target_directory.res_target_directory'); # Read files from Staging directory into Files array opendir my($dh), $inputDir or die "Couldn't open dir '$inputDir': $!"; my @files = readdir $dh; closedir $dh; # get rid of the links to the directories above current directory my $index = 0; $index++ until $files[$index] eq '.'; splice(@files, $index, 1); $index = 0; $index++ until $files[$index] eq '..'; splice(@files, $index, 1); # get server list my @server_list = split(/\,/ , $s_list); # process for each server foreach my $server_list (@server_list) { # connect to server print "ftping file to server: " . $server_list . "\n"; my $sftp = Net::SFTP::Foreign->new($server_list); $sftp->error and die "Unable to stablish SFTP connection: " . $sft +p->error; # process each file to each server foreach my $file (@files) { my $source_ftp_file = $inputDir . "/". $file; my $destination_ftp_file = $outputDir . "/" . $file; print "\n" . $source_ftp_file . "\n"; print $destination_ftp_file . "\n"; # put file to server $sftp->rput($source_ftp_file, $destination_ftp_file, overwrite + => 1) or die "could not put file \n" . $sftp->error; # change files to allow modification by anyone #$sftp->chmod($destination_ftp_file, 0777) or die "count not c +hmod file \n" . $sftp->error; } $sftp->disconnect;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: rput on foreign sftp in perl
by kcott (Archbishop) on Sep 17, 2013 at 02:16 UTC | |
by Anonymous Monk on Sep 17, 2013 at 14:54 UTC | |
by kcott (Archbishop) on Sep 18, 2013 at 01:43 UTC | |
by Anonymous Monk on Sep 18, 2013 at 03:33 UTC | |
by kcott (Archbishop) on Sep 18, 2013 at 05:10 UTC | |
|
Re: rput on foreign sftp in perl
by salva (Canon) on Sep 18, 2013 at 09:39 UTC | |
by Anonymous Monk on Sep 18, 2013 at 11:14 UTC | |
by salva (Canon) on Sep 18, 2013 at 11:33 UTC | |
by Anonymous Monk on Sep 18, 2013 at 21:08 UTC |