LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-20-2007, 05:19 PM   #1
Elguapo
Member
 
Registered: Mar 2005
Distribution: FC7
Posts: 42

Rep: Reputation: 15
Perl FTP


I am working on a perl script that will be used to connect to a ftp server and download a series of files. At this point, I have it working where it connects to the ftp server downloads the files and disconnects. However, there is one more thing I need to tag on to this. After I download all my idx data for the day, I need to download all the images for the day. The images come in a single zip file. The only issue I have is that in side of the img directory there are several days worth of image zip files. I only need to download the current day. The file name of the zip file looks something like this 07202007.zip. I know I can build a string based on the current date, but I would rather do it by datelastmodified. The only thing I can't figure out is how to access that data from the ftp method ls().

Here is my current code.

Code:
#!/usr/bin/perl -w

use Net::FTP;

my $host = $ARGV[0];
my $idxDir = $ARGV[1];
my $imgDir = $ARGV[2];
my $uName = $ARGV[3];
my $uPass = $ARGV[4]

#! Beging connection start
$ftp = Net::FTP->new("${host}", Debug => 0)
	or die "Cannot connect to armlsidx.marketlinx.com: $@";

$ftp->login("${uName}",'${uPass}')
	or die "Cannot login ", $ftp->message;

#! Change working directory to idx dir
$ftp->cwd("${idxDir}")
	or die "Cannot change working directory ", $ftp->message;

#! Loop over idxDir and print file names
$ftp->ls("${idxDir}")
	or die "ls failed ", $ftp->message;
	foreach ($ftp->ls){
		#!$ftp->get("$_","/mnt/homesmart-phx/mls/data/$_");
		print("$_\n");
	}
#! Change working directory img dir
$ftp->cwd("${imgDir}")
	or die "Cannot change working directory ", $ftp->message;
#! Loop over imgDir and print file names
$ftp->ls("${imgDir}")
	or die "ls failed ", $ftp->message;
	foreach($ftp->ls){
		print("$_\n");
	}
#! Close FTP Connection
$ftp->quit;
 
Old 07-21-2007, 12:34 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
File modification time & date information is generally not available from an FTP server. Use the current date to build your file name.

--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp server - perl richwmn Linux - Networking 0 01-06-2006 04:18 PM
Urgent Help: Perl FTP Script Using NET::FTP xboxter Programming 8 05-16-2005 06:57 PM
RH8 with perl ftp across firewall mairot Linux - Networking 1 11-29-2004 02:37 PM
perl and Net::FTP question Tomasfuego Programming 0 12-17-2003 08:13 AM
perl + ftp letmein Linux - General 2 08-06-2003 02:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration