perl ftp - ghdrako/doc_snipets GitHub Wiki
use Net::FTP;
use constant HOST => '10.10.2.48';
use constant DIR => '/u11/ess';
use constant FILE => '\\\\cok_f2\\ftp\\ess_kred\\wnioski\\szk\\dane.txt';
my $ftp = Net::FTP->new(HOST) or die "Couldn't connect: $@\n";
$ftp->login('oracle','ora514') or die $ftp->message;
$ftp->cwd(DIR) or die $ftp->message;
$ftp->put(FILE) or die $ftp->message;
$ftp->quit;
warn "File retrieved successfully.\n";
#!/usr/local/bin/perl -w
use strict;
use Net::FTP;
use IO::File;
use Time::localtime;
local our $FTP_HOST = '<ip>'; # nazwa komputera
local our $IMP_FILE = '.tandem.cok';
local our $XPATERN = '#1aZ$lq37Y';
local our $lok_filename_base = 'base.lock'; # ftp lock file
local our $FTP_BASE = '/ftp1/tlf/'; # ftp directory
local our $IMP_BASE = "/u10/import/data_imp"; # local directory
local our $LOG_PATH = "/u10/import/logs/mv_trans.log"; # log file
local our $PATTERN_BASE = 'xtr[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'; # pattern
local our $ftp;
local our $remotefile;
local our $localfile;
local our @files;
local our $file;
local our $fh;
$ftp = Net::FTP->new($FTP_HOST); # construct object
$ftp->login($IMP_FILE, $XPATERN); # log in
$ftp->cwd($FTP_BASE); # change directory
$fh = IO::File -> new(">> $LOG_PATH")
or die "Opening $LOG_PATH: $!\n";
my $tm = localtime;
print $fh "#####################################\n";
printf $fh (" %04d-%02d-%02d %02d:%02d:%02d\n", $tm->year+1900,
($tm->mon)+1, $tm->mday, $tm->hour, $tm->min, $tm->sec);
@files = $ftp->ls($FTP_BASE)
or die "Can't get a list of files in $FTP_BASE: $!";
for $file (@files)
{
print "file: $file\n";
$remotefile = "$FTP_BASE$file";
$localfile = "$IMP_BASE$file";
if ($file =~ /$PATTERN_BASE/)
{
print "Transfer $remotefile to $localfile\n";
print $fh "Transfer $remotefile to $localfile\n";
$ftp->get($remotefile, $localfile)
or die "Can't fetch $remotefile : $!\n";
}
$ftp->delete($remotefile)
or die "Can't delete $file : $!\n";;
}
$ftp->get($lok_filename_base);
$ftp->quit;
#$ftp = Net::FTP->new($hostname); # construct object
#$ftp->login($username_slog, $password_slog); # log in
#print "slog: ",$ftp->ls($home_slog),"\n";
#print "modyf time:",$ftp->mdtm("$home_base/$lok_filename_slog"),"\n";
#$ftp->get($lok_filename_slog);
#$ftp->quit;