#!/usr/bin/perl use Net::FTP; use Getopt::Function qw(maketrue makevalue); use strict; use warnings; my $VERSION = q{.3}; $::opthandler = new Getopt::Function [ q{version V>version}, q{usage h>usage help>usage}, q{help-opt=s}, q{verbose:i v>verbose}, q{silent:i q>silent quiet>silent}, q{from=s f>from}, q{to=s t>to}, ], { 'from' => [ \&makevalue, q{(required) Location and name of file to send}, q{FILE FROM LOCATION}, ], 'to' => [ \&makevalue, q{(required) Location and name of place to send file to}, q{FILE TO LOCATION}, ], }; $::opthandler->std_opts; $::opthandler->check_opts; if (!$::to) { die(q{You must specify a location to send file to}); } if (!$::from) { die(q{You must specify a location of file to send}); } my ($username,$password,$host,$path) = $::to =~ m#^ftp://([^\:]+)\:([^\@]+)\@([^\/]+)(.*)$#i; my $ftp = Net::FTP->new($host, Debug => 0) or die qq{Error establishing FTP connection: $@}; $ftp->login($username,$password) or die q{FTP login failed: [}, $ftp->code, q{] }, $ftp->message; if ($path) { $ftp->cwd("$path") or die q{FTP cwd failed: [}, $ftp->code, q{] }, $ftp->message; } $ftp->ascii; $ftp->put($::from) or die qq{FTP put of file $::from failed: [} . $ftp->code . q{] } . $ftp->message; $ftp->quit; sub usage { print qq{\ntransferFromTo.pl [options]\n\n}; $::opthandler->list_opts; print qq{\n\nCopy file from one place to another.\n\n}; } sub version { print qq{transferFromTo.pl v $VERSION}; }