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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.