FTP Question

Hi,

I'm attempting to FTP several files using MGET. My problem is that I need to cd to a directory with this naming convention:

YYMMDDHHMM - where the hour and minute is unknown

When I issue cd /ftpdirectory/YYMMDD* from FTP, I receive "No such file or directory

I need a way to get the exact directory name from the remote machine. Here's the script:

ftp hostname <<-EOF
cd /unifi_dev_bkup/database/040106*
bin
mget proddb*
quit
EOF

Thanks in advance.

I don't understand. Does the directory name change every minute? Or do they create a new one every minute? So they have 1440 diectories every day?

A new directory is created each night. The minutes part of the name vary from night-to-night.

The best solution is: don't do that. Including hours, minutes, seconds, microseconds, etc in a daily filename only creates the problem you now face.

If that is not possible, you face a challenging scripting problem. You will need to perform a dir, retrieve the results, determine the proper directory name, and finally cd to that directory.

I demonstrate all of this in my recursive ftp script. You might want to look at it for some ideas.

Thanks for your help, Perderabo.

its a tright dirty but i figured i would toss out the working example befor i head home.

if you want more ftp commands for Net::FTP

#!/usr/bin/perl -w

use Net::FTP;

my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time);
$mon=sprintf("%02d",++$mon); ## add 1 to the month. localtime uses 0-11 for months
$year+=1900; ## add 1900 to the year. localtime starts at 0 from 1900.
$mday=sprintf("%02d",$mday); ## format single digit days to a 2 digit number.
$sec=sprintf("%02d",$sec);
$min=sprintf("%02d",$min);
$hour=sprintf("%02d",$hour);

$dir=$year . $mon . $mday;

my ($host, $user, $pass, $localfs)=( 'your_host', 'ur_username', 'ur_passwd', 'dir_2_download_files_2' );
chdir("$localfs") or die "can not change directory /homes($!)";;

$ftp = Net::FTP->new("$host", Debug => 0 ) or warn "Cannot connect to $host: $@";
$ftp->login("$user","$pass") or warn "Cannot login ", $ftp->message;
$ftp->binary();
my @dir=grep /$dir/,$ftp->ls(".");
$ftp->cwd("$dir[0]");
my @ftp_files=$ftp->ls(".");
for (@ftp_files) { $ftp->get("$_") };
$ftp->quit;

Thanks to you too, Optimus_p.