Search code examples
perlsftpnet-sftp

Upload file over SFTP with Net::SFTP::Foreign


I have a file Test1.csv on my local machine. I have a Perl script to copy this file to a remote location (home/inbound) through an SFTP connection.

Below is my code

use Net::SFTP::Foreign;

use warnings;
use strict;

my $host = "sftp.abcd.com";
my $sftp = Net::SFTP::Foreign->new($host, user => 'user10524', password => 'XXXX');
$sftp->error and die "Something bad happened: " . $sftp->error;

$sftp->put("Test1.csv", "/inbound") or die "put failed: " . $sftp->error;

But I am getting this error, when I run the program:

put failed: Couldn't open remote file '/inbound': No such file


Solution

  • The second parameter of put is a path to the file, not a path to the target folder.

    So it should be:

    $sftp->put("Test1.csv", "/inbound/Test1.csv")