Perl automated file transfer

Hi,

Firstly, I have no experience (at all) with shell scripting. So please, go easy on me :slight_smile:

I did a search for what I was looking for although there were a few things available here and on the net I couldn't find anything tailored to what I am looking for.

Simply put, I have two servers. A GameServer that is accessible through ftp (ftp only) and a WebServer with CPanel for CRON etc. Both running on Linux ofc.

I'm looking for a perl script to run on my WebServer to automatically log into my GameServer via FTP, grab .dem (.dem file extension) files in a certain directory then download them to a certain directory on our WebServer.

It would also be brilliant if there was anyway to check if the file already existed on the WebServer so it wasn't re-downloaded to save on bandwidth.

I'd be grateful if anyone could help me here, again I don't have any experience of shell or perl scripting so if you could kindly give clear instructions that would be great.

Thanks in advance!

Hello,
Have you read the forum rules?
If you have tried something so far, then plz show us the code. If you need raw help like that then plz post this as a job at some other site like rentacoder or so.
No issues.
Regards.

Hi, yeh I guess I do require raw help. Thanks for the reply though.

---------- Post updated 12-24-09 at 08:05 AM ---------- Previous update was 12-23-09 at 03:04 PM ----------

Hi again,

Sorry to double post, I've actually come back this time with a script which I'm having a little trouble with.

I have this so far, intending to do what I set out in my original post:

#!/usr/bin/perl

use strict;
use warnings;
use Net::FTP;
use Net::Netrc;
my $server="remote.ip.address";
my $pageid = "none";
my $pager = "/usr/local/bin/pager";
my $ftpid = "username";
my $pass = "password";
my $remote_cwd = "/srcds_l/cstrike/bin";
#my @files = ls("/srcds_l/cstrike/bin");
my $local_cwd  = "/home/my11969/www/test";

my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3) or
    die (exec "$pager $pageid \"$server: ftp cannot connect: $@\"") ;

$ftp->login("$ftpid","$pass") or
    die (exec "$pager $pageid \"ftp cannot login.\"") ;

$ftp->ascii or
    die (exec "$pager $pageid \"ftp failed binary mode.\"") ;

## get multile files if they exist.

$ftp->cwd($remote_cwd) or die "Can't cd to '$remote_cwd'\n";

#chdir $local_cwd or die "Can't cd to '$local_cwd'\n";

my @files = $ftp->ls($remote_cwd);

for (@files) {
    $ftp->get("$_","$local_cwd/$_") if -f $_;
}

$ftp->quit;

Though when I execute it, I get the following:

Net::FTP>>> Net::FTP(2.77)
Net::FTP>>>   Exporter(5.58)
Net::FTP>>>   Net::Cmd(2.29)
Net::FTP>>>   IO::Socket::INET(1.29)
Net::FTP>>>     IO::Socket(1.29)
Net::FTP>>>       IO::Handle(1.25)

Net::FTP=GLOB(0x88e7118)<<< 220 (vsFTPd 2.0.5)
Net::FTP=GLOB(0x88e7118)>>> USER ******
Net::FTP=GLOB(0x88e7118)<<< 331 Please specify the password.
Net::FTP=GLOB(0x88e7118)>>> PASS ....
Net::FTP=GLOB(0x88e7118)<<< 230 Login successful.
Net::FTP=GLOB(0x88e7118)>>> TYPE A
Net::FTP=GLOB(0x88e7118)<<< 200 Switching to ASCII mode.
Net::FTP=GLOB(0x88e7118)>>> CWD /srcds_l/cstrike/bin
Net::FTP=GLOB(0x88e7118)<<< 250 Directory successfully changed.
Net::FTP=GLOB(0x88e7118)>>> PASV
Net::FTP=GLOB(0x88e7118)<<< 227 Entering Passive Mode (85,234,148,14,104,92)
Net::FTP=GLOB(0x88e7118)>>> NLST /srcds_l/cstrike/bin
Net::FTP=GLOB(0x88e7118)<<< 150 Here comes the directory listing.
Net::FTP=GLOB(0x88e7118)<<< 226 Directory send OK.
Net::FTP=GLOB(0x88e7118)>>> QUIT
Net::FTP=GLOB(0x88e7118)<<< 221 Goodbye.

It looks like it lists the directory but nothing is returned or nothing is downloaded.

I wish to download (get) everything in the said $remote_cwd directory into the $local_cwd directory. Am I missing something here? I'm just bamboozled.

Any help appreciated.