RE: Size checking?

From: Robert Freimuth (rfreimut_at_im.wustl.edu)
Date: 04/19/04


Date: Mon, 19 Apr 2004 11:53:22 -0500
To: <beginners@perl.org>


> I have a perl script that FTPs a file down from another server
[snip]
> I am not sure HOW to do the file size check.

I wrote the following using the LWP::Simple module:

print "beginning download of ", ftp_file_size( $ftp_path_gz ), "\n";

$status = download_file( $ftp_path_gz, $local_path_gz );

sub ftp_file_size
{
        my ( $url ) = @_;

        my @info = head( $url );

        if( scalar @info == 0 )
        {
                return 'unknown size';
        }

        return sprintf( "$info[1] bytes (%.2f MB)", $info[1]/(1024*1024) );
}

sub download_file
{
        my ( $file_to_ftp, $save_filename ) = @_;

        my $status = getstore( $file_to_ftp, $save_filename );

        if( $status == 200 )
        {
                print "Download successful.\n";
                return 1;
        }
        else
        {
                print "An error occurred during the download.\n";
                return 0;
        }
}

> Do you want to do the file check locally or remotely? If local,
>
> perldoc -f stat
> (field 7)
>
> If remotely, Net::FTP provides the 'size' method. You definitely want
> to use Net::FTP for the FTP handling.

Your response seemed pretty adamant about using Net::FTP. Would I be better
off using that module instead of LWP::Simple for this? If so, why?

Thanks,

Bob



Relevant Pages

  • Re: SBS
    ... <end snip> ... Are the branch office computers members of the SBS domain? ... Are you saying there is a web app on the second server? ... Sub: 255.255.255.0 ...
    (microsoft.public.windows.server.sbs)
  • Re: client close the socket. how the server knows?
    ... the server know that the socket is closed from the client side. ... > Private Delegate Sub UpdateListBoxDel(ByVal Data As String) ... > Private Sub Button1_Click(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.vb)
  • .Net remoting doesnt work in Wan area.
    ... i try to broadcast events raised in server to ... Public Sub DoSomething ... Dim del As ... Dim clientProv As New BinaryClientFormatterSinkProvider ...
    (microsoft.public.dotnet.framework)
  • Re: script to create to create tar and place files in the appropriate folder
    ... line would always contain the source server and the destination ... and Archive::Tar to put them into a tarball (preserving ... Currently the instructions are coming from DATA, ... sub fetch_files ...
    (perl.beginners)
  • Re: How to get fastForward to work in the Windows Media Player Control?
    ... Sub ShutMeDown ... WMP is *client side*. ... Even if you could try to run WMP somehow at the server end, ... "Player" is not a child of Form1, it's a child of the Document object. ...
    (microsoft.public.windowsmedia.player.web)