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;
In reply to rput on foreign sftp in perl by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |