Friday, 26 September 2008

Net::FTP ... be careful with modes

Took ages for Sam and I to figure out why the files we were downloading could not be opened. It was a simple case of not specifying the format for Net::FTP to transfer our files in.


#! /usr/bin/env perl

use 5.010_000;

use strict;
use warnings;

use Archive::Extract;
use Net::FTP;

my $data_file = shift;
my $outputdir = shift;
my $ftp_wtccc = Net::FTP->new(
Host => 'ftp.sanger.ac.uk',
Debug => 0,
Timeout => 300,
Passive => 1,
) or die 'Could not connect to ftp.sanger.ac.uk';

$ftp_wtccc->login( "********", "********" )
or die "Cannot login ", $ftp_wtccc->message;

if ( grep {m/$data_file/xms} $ftp_wtccc->ls ) {
$ftp_wtccc->binary;
$ftp_wtccc->get($data_file) or die "Could not get $data_file";
}

$ftp_wtccc->quit;

my $archive =
Archive::Extract->new( archive => $data_file )
->extract( to => $outputdir // '/tmp' );

exit 0;

No comments: