Reputation: 21
my ( $addr, $usr, $pwd, $ascii, $active, $timeout ) = @_;
my $ftp;
# Set up new FTP with active mode and user-specified timeout...
if ( $active and $timeout )
{
$ftp = Net::FTP -> new ( $addr, Passive => 0, Timeout => $timeout )
or die "Failed to connect to FTP (w/ active, timeout): $addr";
}
# Login to new FTP
$ftp -> login ( $usr, $pwd )
or die "Failed to login to FTP: " . $ftp->message;
# Set ASCII or binary transfer modes
if ( $ascii ) { $ftp -> ascii(); }
else { $ftp -> binary(); }
print "LOGIN: $addr\n";
return $ftp;
}
Can someone explain what the above is doing? it's login into the ftp and then it returns it? what is it actually returning? is this for uploading or downloading?
Upvotes: 0
Views: 91
Reputation: 107080
You can do a couple of things:
$ftp
is a reference to a hash that contains a lot of various entries.Reading through these two tutorials will explain everything you need to know. I could try to answer your question directly, but I'd end up pretty much repeating the tutorials, and probably not do as good a job.
Use the Data::Dumper
module to dump out $ftp
before your return statement, and you'll get a better idea what it really looks like. Then read the tutorials.
Upvotes: 0
Reputation: 129481
It returns an object of the class Net::FTP (this way, the FTP connection is already established, and your caller code can use that object for up/downloading the files as you wish without logging in/connecting).
To learn how to use Net::FTP objects, see examples in its documentation, typically $ftp->put()
and $ftp->get()
to upload/download files.
Upvotes: 4
Reputation:
It doesn't initiate any file transfers. It just returns an object that you can use to make requests. When it returns, the FTP connection is established and the authentication is done, and the server is waiting for the next command.
Upvotes: 1