FTP into a server using specific usernames
Posted
by
user1854765
on Stack Overflow
See other posts from Stack Overflow
or by user1854765
Published on 2012-12-17T18:27:49Z
Indexed on
2012/12/17
23:03 UTC
Read the original article
Hit count: 250
I am trying to ftp into a server, once I'm there, I want to get a file, then put it back after sleeping for 5 minutes. I have that part correct, but i added to the code, two variables that will be inputted when the code is executed. The user will input the username they want to connect with. I am having trouble connecting though. When I input the username t14pb, it still goes to the the first if statement, as if I said t14pmds. here is the code:
#!/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: $!";
}
© Stack Overflow or respective owner