Perl automated file transfer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl automated file transfer
# 1  
Old 12-23-2009
Perl automated file transfer

Hi,

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

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!
# 2  
Old 12-23-2009
Quote:
Originally Posted by lastrider
Hi,

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

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.
# 3  
Old 12-24-2009
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:

Code:
#!/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:

Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automated File Transfer Script

We are receiving data feed files in SFTP location daily. so the folder structure in SFTP location is abc/def/studyname_1/outbound/zipped files So we will be getting different studies and for each study a folder is created abc/def/studyname_2/outbound/zipped files , ... (7 Replies)
Discussion started by: Sidhant
7 Replies

2. Shell Programming and Scripting

Need help for automated pickup of file based on a priority

Hi experts, I am facing a problem right now.I have to automate the pickup of files based on a priority.The scenario is as below: 1) There will be files from Mon-Fri with Mon file being named as abc_def_01_YYYYMMDD and Tue file being abc_def_02_YYYYMMDD and so forth till Friday's file which... (1 Reply)
Discussion started by: vikramgk9
1 Replies

3. Shell Programming and Scripting

How to transfer file from one PC to another using PERL?

Hi All I have two PC connected with each other via LAN cable. In one of the PC the Perl is installed. What I want to do is transfer the data from one PC to another via Perl. Is it possible to do this. ---------- Post updated at 11:31 PM ---------- Previous update was at 07:01 AM ----------... (10 Replies)
Discussion started by: parthmittal2007
10 Replies

4. UNIX for Advanced & Expert Users

perl script to transfer newly generated files by scp

Hi all, I have root directory on server 1 say A and having sub directory B now my application generates output files and put in sub directory B. now i need to transfer these files from server1 to server2 by scp which is having same directory structure A and sub directory B I have tried... (2 Replies)
Discussion started by: tushar_spatil
2 Replies

5. Shell Programming and Scripting

Automated script to take 1000 records from the file every week.

I have a file having n number of records .i want first 1000 records from the file and store in temporary file to process on sunday. I want script should should automatically take the next 1000 records for processing on next sunday. can we do it using head and tail head -1000 | tail... (2 Replies)
Discussion started by: sonam273
2 Replies

6. Shell Programming and Scripting

C, sh, perl, system(): Can't transfer a return code appropriately: help, pls

I am using a perl-script from C-code, executing it by the 'system(..)' comand. The problem is to return the perl-return code to the C correctly. Default the 'system()' shell is Bourne: sh My try: (perl_src.c_pl - the perl script; t_sys - C-program with system() call (I will show it... (7 Replies)
Discussion started by: alex_5161
7 Replies

7. UNIX and Linux Applications

Automated file transfer

I want to automate the file transfer from a remote site to my pc over a WAN. Can anyone please suggest an industry standard secure file transfer tool for a windows environment? I am looking for an industry accepted, more secure than traditional FTP. Thanks! (1 Reply)
Discussion started by: damienjine
1 Replies

8. Shell Programming and Scripting

moving a file to a new folder and automated ftp

how to move a file to a different folder after an automated FTP . (1 Reply)
Discussion started by: dineshr85
1 Replies

9. Shell Programming and Scripting

Data transfer from DB2 to Sybase using Perl?

Hi, Good Morning everybody. I need to write a perl script which will get some data from DB2 table and then put it into Sybase table. I have the experience in Oracle and Unix but new to these perl, DB2 and Sybase technologies. Appreciate if any one can suggest with a sample code. Thanks... (1 Reply)
Discussion started by: rajus19
1 Replies

10. Shell Programming and Scripting

Perl scirpt for automatic file transfer

Hi , can any one help me with a perl script for automating file transfer ? At each step i need to check for the success or failure . I am trying to connect to the target system for a specified number of times.if it doesnt connect even after 3 retries then the script should exit. and i have to... (8 Replies)
Discussion started by: sveera
8 Replies
Login or Register to Ask a Question