LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-20-2004, 05:34 PM   #1
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Rep: Reputation: 51
need a perlscript to read from a text file and transfer files via ftp


hi

I know sometimes it's not easy, but I need a perl script rather urgently

I get 5 times a day, 3 files transfered : one info.txt and two data files:

info.txt
SN00001
SN00002

the name of info.txt never changed, but names of data files yes.
but the names in info.txt file (left) are always the same
like names of data files.

info.txt file looks:

-------------------------------------------------------------

SN00001 RN20001

SN00002 RN20002

--------------------------------------------------------------

the perl script should first open the info.txt file,
read the name of the first file (like left in info.txt),
rename the first file to RN20001 (like right in info.txt ),
transfer via ftp, wait 5 minutes,
rename the second file to RN20002 and transfer via ftp
to the same remote server.
I mean to wait for 5 minutes before the second file will be transfered.
this is very important.

and this script should not transfer any files without info.txt


if someone can help me would be great, before I am lost !

best regards
cccc

Last edited by cccc; 02-21-2004 at 07:56 AM.
 
Old 02-21-2004, 02:53 PM   #2
linuxxed
Member
 
Registered: Feb 2004
Posts: 273

Rep: Reputation: 30
Re: need a perlscript to read from a text file and transfer files via ftp

Quote:
Originally posted by cccc
hi

I know sometimes it's not easy, but I need a perl script rather urgently

I get 5 times a day, 3 files transfered : one info.txt and two data files:

info.txt
SN00001
SN00002

the name of info.txt never changed, but names of data files yes.
but the names in info.txt file (left) are always the same
like names of data files.

info.txt file looks:

-------------------------------------------------------------

SN00001 RN20001

SN00002 RN20002

--------------------------------------------------------------

the perl script should first open the info.txt file,
read the name of the first file (like left in info.txt),
rename the first file to RN20001 (like right in info.txt ),
transfer via ftp, wait 5 minutes,
rename the second file to RN20002 and transfer via ftp
to the same remote server.
I mean to wait for 5 minutes before the second file will be transfered.
this is very important.

and this script should not transfer any files without info.txt


if someone can help me would be great, before I am lost !

best regards
cccc

I'm not a perl dude but this should be easy in shell. Run it five times a day using cron. ALtenatively you can write a generic script which polls a give directory in an infinite loop and performs the necessary action .. you get the idea.

First create a .netrc file and put the ftp user and password there

#/bin/sh

ftpdata(){
echo "ftping data"
ftp $REMOTESERVER<<EOF
cd $REMOTEDIR
put $DATADIR/LOCALFILE $REMOTEDIR/REMOTEFILE
bye
EOF
}

DATADIR=your data directory when files are received
ARCHIVEDIR=where you want the old data archived
REMOTEDIR=directory where you want ftping
REMOTESERVER=remote host
LOCALFILE=
REMOTEFILE=

if [ ! -f $DATADIR/info.txt ]; then
echo "Nothing to process"
exit 0
fi

LOCALFILE=`awk '{ if ( NF == 0 ) print $1}' $DATADIR/info.txt`
REMOTEFILE=`awk '{ if ( NF == 0 ) print $2}' $DATADIR/info.txt`

ftpdata ;
mv $DATADIR/LOCALFILE $ARCHIVEDIR/$LOCALFILE.`date +'%d%m%Y.%T'`
sleep 300

LOCALFILE=`awk '{ if ( NF == 1 ) print $1}' $DATADIR/info.txt`
REMOTEFILE=`awk '{ if ( NF == 1 ) print $2}' $DATADIR/info.txt`

ftpdata ;
mv $DATADIR/LOCALFILE $ARCHIVEDIR/$LOCALFILE.`date +'%d%m%Y.%T'`
mv $DATADIR/info.txt $ARCHIVEDIR/info.txt.`date +'%d%m%Y.%T'`
 
Old 02-21-2004, 06:18 PM   #3
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
hi linuxxed

thank you very much !

it's a great script and works well.

kind regards
cccc

Last edited by cccc; 02-24-2004 at 01:47 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
transfer files over the web, ftp, http or other? buffed317 Linux - General 7 03-08-2005 09:25 PM
I need perlscript to convert text file in UTF-16 cccc Programming 3 07-04-2004 04:08 AM
Perlscript doesn't read selected Pull-down Menu cccc Programming 12 05-27-2004 09:30 AM
I'm looking for perlscript to delete some files via ftp cccc Programming 1 02-24-2004 01:56 AM
Can I make a Cron job to synch/transfer a file from a folder to another FTP?... read efishta Linux - General 6 07-19-2003 10:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration