#!/usr/bin/env perl

# Copyright (C) 2005  Joshua Hoblitt
#
# $Id: psftp-get,v 1.1 2005-10-15 01:27:33 jhoblitt Exp $

use strict;
use warnings FATAL => qw( all );

use vars qw( $VERSION );
$VERSION = '0.01';

use PS::IPP::PSFTP;

use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
use Pod::Usage qw( pod2usage );

my ($url, $size, $md5, $filename);

GetOptions(
    'url|u=s'       => \$url,
    'size|s=s'      => \$size,
    'md5|m=s'       => \$md5,
    'filename|f=s'  => \$filename,
) || pod2usage( 2 );

pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
pod2usage(
    -msg => "Required options: --url --filename",
    -exitval => 3,
) unless defined $url and defined $filename;

my $status = PS::IPP::PSFTP->get_file(
    url         => $url,
    size        => $size,
    md5         => $md5,
    filename    => $filename,
);

unless ($status) {
    exit(4);
}

__END__

=pod

=head1 NAME

psftp-get - download a file from a PSFTP server

=head1 SYNOPSIS

    psftp-get --url <url> --filename <filename> [--size <nbytes>] [--md5 <hex>]

=head1 DESCRIPTION

=head1 OPTIONS

=over 4

=item * --url|-u <url>

The URL of the file to be retrieved.

=item * --filename|-f <filename>

The name to use when writing the file to disk.

=item * --size|-s <nbytes>

The size of the file in bytes.

Optional, the size check is skipped if no value is specified. 

=item * --md5|-m <hex>

The md5 checksum of the file in hex.

Optional, the md5check is skipped if no value is specified. 

=back

=head1 CREDITS

Just me, myself, and I.

=head1 SUPPORT

Please contact the author directly via e-mail.

=head1 AUTHOR

Joshua Hoblitt <jhoblitt@cpan.org>

=head1 COPYRIGHT

Copyright (C) 2005  Joshua Hoblitt.  All rights reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA  02111-1307, USA.

The full text of the license can be found in the L<perlgpl> Pod as supplied
with Perl 5.8.1 and later.

=head1 SEE ALSO

L<PS::IPP::PSFTP>

=cut
