我正在尝试 ftp 进入服务器,一旦我在那里,我想获取一个文件,然后在休眠 5 分钟后将其放回。我的那部分是正确的,但是我在代码中添加了两个将在执行代码时输入的变量。用户将输入他们想要连接的用户名。我在连接时遇到问题。当我输入用户名 t14pb 时,它仍然转到第一个 if 语句,好像我说的是 t14pmds。这是代码:
#!/usr/bin/perl
use Net::FTP;
$host = "fd00p02";
$username = "$ARGV[0]";
$ftpdir = "/";
$file = "$ARGV[1]";
print "$username\n";
print "$file\n";
if ($username == t14pmds) {
$password = "test1";
$ftp = Net::FTP->new($host) or die "Error connecting to $host: $!";
$ftp->login($username, $password) or die "Login failed: $!";
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";
$ftp->get($file) or die "Can't get $file: $!";
sleep 5;
$ftp->put($file) or die "Can't put $file: $!";
$ftp->quit or die "Error closing ftp connection: $!";
}
if ($username == t14pb) {
$password = "test2";
$ftp = Net::FTP->new($host) or die "Error connecting to $host: $!";
$ftp->login($username, $password) or die "Login failed: $!";
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";
$ftp->get($file) or die "Can't get $file: $!";
sleep 5;
$ftp->put($file) or die "Can't put $file: $!";
$ftp->quit or die "Error closing ftp connection: $!";
}
if ($username == t14pmds_out) {
$password = "test3";
$ftp = Net::FTP->new($host) or die "Error connecting to $host: $!";
$ftp->login($username, $password) or die "Login failed: $!";
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";
$ftp->get($file) or die "Can't get $file: $!";
sleep 5;
$ftp->put($file) or die "Can't put $file: $!";
$ftp->quit or die "Error closing ftp connection: $!";
}
if ($username == t14fiserv) {
$password = "test4";
$ftp = Net::FTP->new($host) or die "Error connecting to $host: $!";
$ftp->login($username, $password) or die "Login failed: $!";
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";
$ftp->get($file) or die "Can't get $file: $!";
sleep 5;
$ftp->put($file) or die "Can't put $file: $!";
$ftp->quit or die "Error closing ftp connection: $!";
}