Determining File Size Using FTP 
Author Message
 Determining File Size Using FTP

Does anyone know a quick-and-dirty way to retrieve the size of a file,
accessible through FTP,  without necessarily parsing the directory
information?

For example, to get the size of a file using http is simple:
    use LWP::UserAgent;
    $file = http://www.*-*-*.com/ ;

    print $templist[1];

But if $file was, for example, ftp://domain.com/directory/paper.ps.gz, this
would not work. It seems that one must:
    1) parse the URL for the ftp server name, the directory name and the
file name
    2) use Net::FTP to login, change directory, get a dir listing, and parse
the listing to get the file size.

If there is not already a module that performs this function, is there one
that reliably parses URLs for directory and file name information (it
doesn't seem that URI::URL does this)? I have already written some code to
parse the directory listing if I have to.

Thanks very much, in advance, for your help.

Larry Kite



Thu, 09 Jan 2003 03:00:00 GMT  
 Determining File Size Using FTP
: If there is not already a module that performs this function, is there one
: that reliably parses URLs for directory and file name information (it
: doesn't seem that URI::URL does this)?

What makes you think URI::URL can't do this?

#!perl -w
use strict;

use URI::URL;
use Net::FTP;

my $url = URI::URL->new( 'ftp://localhost/directory/paper.ps.gz' );

$url->scheme eq 'ftp'
        or die "No FTP URL";
my $ftp = Net::FTP->new( $url->host, Port => $url->port )
        or die "No Net::FTP object";
$ftp->login( $url->user, $url->password )
        or die "FTP login failed";

$ftp->quit;

$" = "\n";

__END__

This gives

F:\TEMP\perl> perl ftpdir.pl
            523879      A          01-01-98   09:12  paper.ps.gz

on my OS/2 system (which shows another problem, IMHO: the output of a LIST
FTP command isn't standardized, and changes with the FTP server).

cu,
  Martin
--
One OS to rule them all       | Martin Vorlaender  |  VMS & WNT programmer

One OS to bring them all      |       http://www.pdv-systeme.de/users/martinv/



Thu, 09 Jan 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Determining File Size with FTP

2. Can't get size value back when using $ftp->size

3. Differences in the file size reported by Net::FTP->size and ls -l

4. file upload, determining file type, size, format

5. CGI.pm Bug: file upload file size mismatch when file size is close to buffer size

6. Determining file sizes

7. Newbie Q: Determining size of a binary file

8. REQUEST: Need jelp determining FILE SIZE...

9. file size limits of perl Net::ftp

10. Net::FTP File Size Limit?

11. Monitoring file size during net::ftp

12. Does anyone know how to determine window size?

 

 
Powered by phpBB® Forum Software