The following code is intended to simply transfer a file stored on hard disk to a remote sftp server:

sub sftp_transfer { my ( $ftp_url, $ftp_user, $ftp_passwd, $ftp_dir, $output_file_path +) = @_; if ( $debug ) { print "&sftp_transfer: "; print "Host: $ftp_url\n"; print "User: $ftp_user\n"; print "Password: $ftp_passwd\n"; print "Dir: $ftp_dir\n"; } my %conn = ( "user" => $ftp_user, "password" => $ftp_passwd, "port" => 2222, "autoflush" => 1 ); my $ftp=Net::SFTP::Foreign->new( $ftp_url, %conn ); if ( $ftp->error ) { $err_occured = 1; $error_msg ="SFTP: Cannot connect to sftp-server $ftp_url: " . $ftp->err +or; die ( "\n" ) }; $ftp->setcwd( $ftp_dir ) or do { $err_occured = 1; $error_msg = "SFTP: Cannot cd into $ftp_dir: " . $ftp->error; die ( "\n" ) }; my $output_file_name = basename( $output_file_path ); $ftp->put( $output_file_path, $output_file_name ) or do { $err_occured = 1; $error_msg = "SFTP: Cannot upload file $output_file_path: " . $f +tp->error; die ( "\n" ) }; }

Output (with $debug == 1)

&sftp_transfer: Host: example.com User: user Password: *** Dir: /POS/21/2100139 Password Authentication

On the command line, file transfer works flawlessly. When applying the above code, the files transferred have zero Byte size, although not being empty prior to transfer, The sending client is a Linux box, I not know about the server. Any ideas whatis going wrong here?


In reply to Net::Sftp::Foreign writes empty files to FTP server by Bloehdian

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.