You would probably save alot of code and frustration using this module. Net::FTP is a class implementing a simple FTP client in Perl as described in RFC959. It provides wrappers for a subset of the RFC959 commands.
use Net::FTP;
$ftp = Net::FTP->new("some.host.name", Debug => 0)
or die "Cannot connect to some.host.name: $@";
$ftp->login("$user","$Password")
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;
As for the user prompt, if you can use STDIN the following should work.
print "Enter username or press enter for anonymous: ";
my $user = <STDIN>;
chomp $user;
if (length($user //= '')) {$user="anonymous";$password="INSERTPASSWORD"}
else {
print "Enter password for $user: ";
my $password = <STDIN>;
chomp $password;
}
I would request the user and password as early as possible in your script, and then you can pass it to the $ftp object. Using the module is better then using exec or pipes as it will have built in error reporting and is going to be easy to OO.
Hope this helps and comment if you need more help.