要求:
我想创建一个脚本,使用perl将文件从本地系统上传到FTP服务器。
示例代码:
use Net::FTP;
$ftp = Net::FTP->new("some.host.name", Debug => 0)
or die "Cannot connect to some.host.name: $@";
$ftp->login("anonymous",'-anonymous@')
or die "Cannot login ", $ftp->message;
$ftp->cwd("/pub")
or die "Cannot change working directory ", $ftp->message;
$ftp->get("that.file")
or die "get failed ", $ftp->message;
$ftp->quit;
P.S:Perl中的新手。
答案 0 :(得分:5)
您可以尝试使用此代码,这对我来说很合适
use strict;
use warnings;
use Net::FTP;
my ($ftp, $host, $user, $pass, $dir, $fpath);
$host = "";
$user = "";
$pass = "";
$dir = "";
$fpath = "";
$ftp = Net::FTP->new($host, Debug => 0);
$ftp->login($user, $pass) || die $ftp->message;
$ftp->cwd($dir);
$ftp->put($fpath) || die $ftp->message;
$ftp->quit;
print $ftp->message;