Bloehdian has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Sftp::Foreign writes empty files to FTP server
by salva (Canon) on Feb 08, 2020 at 10:11 UTC | |
|
Re: Net::Sftp::Foreign writes empty files to FTP server
by soonix (Chancellor) on Feb 07, 2020 at 16:39 UTC | |
|
Re: Net::Sftp::Foreign writes empty files to FTP server
by Naren (Initiate) on Jan 06, 2022 at 18:13 UTC |