Perl (Scripting) - Getting Started with Net::SFTP

by
Jeremy Canfield |
Updated: October 29 2020
| Perl (Scripting) articles
Before using the Perl SFTP module, you may want to use the ftp command (Linux) to determine if you are able to connect and authenticate onto the target FTP server.
This assumes you have installed the Net::SFTP module on your Perl system. Following is the most simple example of how to GET or PUT using the SFTP module.
#!/usr/bin/perl
use strict;
use warnings;
use Net::SFTP;
my $host = "your_hostname";
my %args = ();
$args{user} = "your_username";
$args{password} = "your_password";
$args{debug} = "true";
my $sftp = Net::SFTP->new($host, %args);
$sftp->get("/path/to/remote/foo.txt", "/path/to/local/foo.txt");
$sftp->put("/path/to/local/foo.txt", "/path/to/remote/foo.txt");
Did you find this article helpful?
If so, consider buying me a coffee over at