Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding file size and modified date

Status
Not open for further replies.

GZPM

IS-IT--Management
Jan 20, 2006
18
US
This is my first post, and after looking through various threads I still can't find a solution to below. A little help would be GREATLY appreciated.

Below script works swell, but now i've also been asked to include file size and modified date. I've tried a few i found on various threads, but to no avail.

Here is the original WORKING script without above requests.

Thanks, GZPM

#!/usr/bin/perl

#use strict;

use Net::FTP;

$username = "abc";
$password = "123";
$home = "/my_folder";
@directory = ("balkema","abvil","abc","abdo","abd");


$ftp = Net::FTP->new("myftpsite.com");

$ftp->login($username, $password);

foreach my $a (@directory) {


$ftp->cwd($a);

@list = $ftp->ls("*.xml");


foreach my $b (@list) {

print "$a - $b\n"
}

$ftp->cwd($home);

}

 
I haven't used used Net::FTP before, but looking at the docs it appears that you can use $ftp->mdtm(FILE) for the mod time and $ftp->(size) for the file size. Give this a shot and see how it works:
Code:
foreach my $dir (@directory) {
    $ftp->cwd($dir);
    @list = $ftp->ls("*.xml");

    foreach my $file (@list) {
        print "$dir\n";
        print "\t", join(" - ", $file, $ftp->size($file), $ftp->mdtm($file));
    }

    $ftp->cwd($home);
}
Also, you might want to take a look at perldoc Net::FTP or you can look at this link.
 
Hi rharsh,

thx for the info. It worked, except now I get the size/mdtm in binary (i think?). Is there a way to convert them to size to KB and mdtm to m/d/yyyy h:mm AM/PM?

GZPM

I have already read the cpan page, but the syntax is what gets me in trouble.
 
here's an example of what i get:

file_name|size|mdtm
CDC_02172006_onix21.xml - 1284696 - 1140294143

and here's what I see for above file in the FTP server
CDC_02172006_onix21.xml - 1,212KB - 2/18/2006 3:22 PM

As you can see, even though there is a date in the file name, it is usually different than the mdtm, hence the reason that's the one I need to record (along with size).

again, thanks the response.
 
Here are a couple suggestions for you, see if you can work out the problems and let us know if you get hung up.

The easiest one first - the time isn't binary, it's epoch time. Take a look at the localtime function, it should do what you need (perldoc -f localtime).

The file sizes, as the documentation states, are in bytes. There are plenty of ways to convert your file sizes to something more useful. Take a look at thread219-1118565 for a decent discussion on code for doing those conversions. Also note that the file sizes could vary because a copy on the remote server and on your local machine.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top