Search notes:

Perl module Net::FTP: logging in with Net::Netrc

#!/usr/bin/perl
use warnings;
use strict;
use Net::FTP;
use Net::Netrc;

my $hostname = shift or die "No hostname given";
die "~/.netrc is needed" unless glob '~/.netrc';

my ($username, $password) = Net::Netrc -> lookup($hostname) -> lpa;

my $ftp = Net::FTP->new($hostname, Debug => 0) or die "Could not open connection to $hostname";
$ftp -> login($username, $password) or die "$username, $password";

printf "Logged in, current working directory: %s\n", $ftp->pwd;

print join "\n", $ftp -> ls;
Github repository PerlModules, path: /Net/FTP/login-with-Net-Netrc.pl
Net::Netrc seems to also work on Windows if there is a .netrc file in C:\users\username.

See also

Net::FTP, Net::Netrc
Perl modules.

Index