Perl6 Net::FTP Sample

#!/usr/bin/env perl6

use Net::FTP;

my @locals = (
	"/update/",
);

my @remotes = (
	"/usbip/",
);

my $ftp = Net::FTP.new(:host<192.168.8.179>, :user<ftpup>, :pass<123456>, :passive);

$ftp.login();

for (@locals Z @remotes) -> ($local, $remote) {
	for $local.IO.dir {
		my ($lpath, $rpath);

		$lpath = $_.abspath();
		$rpath = $remote ~ $_.basename();

		if $ftp.put($lpath, $rpath, :binary) {
			say "T\t$lpath ===> $rpath";
			if unlink($lpath) {
				say 'unlink ' ~ $lpath;
			}
		} else {
			say "F\t$lpath =/=> $rpath [ " ~ $ftp.code() ~ ' ' ~ $ftp.msg ~ "]";
		}
	}
}

$ftp.quit();

编程技巧