CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
How do you FTP in a perl program?



Feb 28, 2000, 3:08 PM

Post #1 of 2 (1506 views)
How do you FTP in a perl program? Can't Post


I was wondering how to ftp a file off of a non-anonymous (meaning username & password protected) with a perl script. Basically, I need the site I am working on to be totally automated. It has to download a zip file of end-of-the-day stock quotes, unzip it, and then import it into a mysql database.

I plan on using crontab to call the program at 5:30pm eastern Monday through Friday.

Anyway, the only part I don't know how to do is to write a script that will download a file from a non-anonymous ftp.

For an example, assume the file is located in pub/download and the file name is a variable since the names are based on what day it is (e.g. would be todays file) and the login is "stock" and the password is "market" on port 21.

I appreciate any help...
if this isn't possible in perl, are there any ideas?


Administrator / Moderator

Feb 28, 2000, 7:52 PM

Post #2 of 2 (1506 views)
Re: How do you FTP in a perl program? [In reply to] Can't Post

You can use the module Net::FTP to do what you need. You can download Net::FTP if it's not already installed on your account at CPAN. The documentation is there as well.

In a nutshell, here's some of the commands you can use with Net::FTP that will log into a "non-anonymous" account and upload, download and delete files:

use Net::FTP;

# Create new FTP object
$ftp = Net::FTP->new( $domain );

# Log into $domain";
$ftp->login( $username, $password ) or die
"Couldn't log in using usr: $username and pw: $password.\n";

# Change working remote directory
$ftp->cwd( $fullpathtodirectory );

# See where you currently are on the remote server
$dir = $ftp->pwd();

# Switch to ASCII mode

# Delete a file
$ftp->delete( $filetodelete ) or die "Could not delete $filetodelete.\n";
print "Upload successful.<P>";

# Upload a file
$ftp->put( $filetoupload, $newfilename ) or die
"Could not upload $filetoupload into $dir.\n";

# Get a file
$ftp->get( $filetoretrieve );

# Make a habit of always including the quit line Smile


Good luck!

(This post was edited by Jasmine on Mar 2, 2002, 10:09 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives