The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Automatic name file with increase steiner Shell Programming and Scripting 6 05-29-2007 12:14 AM
Using Public key in Shell scirpt LochanM Shell Programming and Scripting 1 07-11-2006 05:33 AM
Data transfer from DB2 to Sybase using Perl? rajus19 Shell Programming and Scripting 1 07-08-2006 10:23 PM
Scirpt moving file before it is finished writing Haleja001 Shell Programming and Scripting 3 01-12-2006 09:23 PM
unix automatic file transfer tagem UNIX for Advanced & Expert Users 4 11-14-2005 05:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-13-2005
Registered User
 

Join Date: Mar 2005
Location: INDIA
Posts: 60
Red face 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 take the list of files on the source directory and should FTP each one to the target directory.
And i have to record the number of files that could be sent successfully and the number of failures and also save the names of the files for reporting.
Please help.
Thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 04-13-2005
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,467
You need to use the Net::FTP module to perform the actual FTP'ing. Reading the source directory on disk can be with primitive functions such as opendir() and readdir(). Or there are modules on CPAN that will do this with a more OO syntax such as DirHandle or IO::Dir.

The other requirements are trivial, as Net::FTP functions give return values that allow you to check whether each operation is successful. Maybe you can try with these lines of thought first.
Reply With Quote
  #3  
Old 04-14-2005
Registered User
 

Join Date: Mar 2005
Location: INDIA
Posts: 60
Talking

Thank you.
but i already wrote the basic code for file transfer using perl.
all i want is a more detailed one with the conditions that i mentioned.
regards
srini
Reply With Quote
  #4  
Old 04-14-2005
Registered User
 

Join Date: Mar 2005
Location: INDIA
Posts: 60
Red face Automate FTP using Perl

Hi friends, i have written a basic script for automating ftp of files from source directory to a destination directory on a different host. But how can i get the list of files in the source directory so that i can keep track of the files which went successfully and unsuccessful files ? thanks in advance srini
Reply With Quote
  #5  
Old 04-14-2005
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,467
The primitive way (without considering recursive dir listing) is very easy and can be along the lines of

Code:
$MY_DIR="/my/dir";
opendir(DIR, $MY_DIR);
my @files = readdir(DIR);
my @plain_files = sort map {
    (-f "$MY_DIR/$_")?($_):()
} @files;
foreach (@plain_files) {
    # FTP of $_ here (e.g. /my/dir/myfile)
}
Reply With Quote
  #6  
Old 04-14-2005
Registered User
 

Join Date: Mar 2005
Location: INDIA
Posts: 60
Talking perl ftp

Hi cbkihong,
Thank you so much for the code.
it works well.
actually i had some other problem which is solved with your code.
excellant job cbkihong.
bye
srini
Reply With Quote
  #7  
Old 04-14-2005
Registered User
 

Join Date: Mar 2005
Location: INDIA
Posts: 60
Red face perl ftp

Hi cbkihong,
I am doing an iteration on each file in the local directory and then if the ftp fails then i am doing a retry for a fixed number of times.
if ftp fails the first time then i am saying continue to the next trial
or else to break.
for this i wrote the code as
===============
for($try=1;$try<=$retry_file_ftp;$try++)
{
print "filename is ::$i\n";
$ftp->put("$local_directory/$i") or $newerr=1;

if ($newerr ==1)
continue;
else
break;
}
}
==================
but its giving some syntax error at continue.
i am not able to figure it out .
can u please help ?
thanks in advance
bye
srini
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0