etilem.free.pl


Code Index:


NAME

etilem.free.pl <action> <file> <remote_dir>


DESCRIPTION

Take <action (get/put/del)> over <file> in the FTP <remote_dir>.

Doesn't yet support directories, sorry dudes ;)


COPYRIGHT

Copyright 2010 Etienne LEMEE <coding AT etilem DOT net>

This piece of code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


#!/usr/bin/perl -w

use strict;
use Net::FTP::Etilem_free;

@ARGV > 2 or die << "USAGE";

usage: $0 <action> <file> <remote_dir>

take <action (get/put/del)> over <file> in the FTP <remote_dir>.

doesn't yet support directories, sorry dudes ;)
USAGE

my (%methods, $action, $file, $remote_dir, $link);

%methods = (get => \&get, put => \&put, del => \&del);
$action = shift;
$file = shift;
$remote_dir = shift;

die "Don't know how to handle method $action\n" unless($methods{$action});
$link = new Net::FTP::Etilem_free;
$link->ftp_connect;
$link->ftp_changedir($remote_dir);
$methods{$action}->($link, $file);
$link->ftp_quit;

sub get {
    my ($link, $file) = @_;
    $link->ftp_get($file);
}

sub put {
    my ($link, $file) = @_;
    $link->ftp_put($file);
}

sub del {
    my ($link, $file) = @_;
    $link->ftp_del($file);
}