LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-05-2006, 10:19 PM   #1
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Rep: Reputation: 15
FTP Shell Scripting Help


My original FTP script was pulling every file with an extension of *.txt - And now, I want to modify the script to pull just one specific file *Myfile20060605AABB.txt

However, it's not working and doesn't display any errors. Attached is the script for you experts to see what I was trying to do. By the way, within the script I also displayed on how I deal with the file permission from the Windows environment.

As you can see, I am a newbie trying to write a Linux script.

Please help!!

Thank you in advance.

Jorge

#!/bin/sh
HOST='10.0.0.1'
USER='ftpprocess'
PASSWD='ftp-ftp'
DATE=`date +%m%d`
##FILE='*txt'
##FILE1='*TXT'
FILE=FILE='Myfile*2006'$DATE*
log=/tmp/xtrans.log
test=/tmp/getfile.test
cd /ftpin/ffi
dat=`date`
echo $dat >> $log


ftp -n -i $HOST >> $log 2>> $log <<END_fgSCRIPT
quote USER $USER
quote PASS $PASSWD
cd ..
asci
cd ABC_FTP
cd IN

mget $FILE 2>>$log
mdelete $FILE
quit
END_fgSCRIPT
cd /ftpin/ffi
ls *.txt > $test 2>>/tmp/log
numline=`cat $test|wc -l`

if [ "$numline" -gt 0 ]; then
echo "Following files have been pulled from ftp server">>$log
cat $test>>$log


cp /ftpin/ffi/*txt /home/user/ftp_1/IN/ 2>> $log
exec < $test
while read line
do
chmod 666 /user/ftp_1/IN/$line 2>>$log
chown ftp-user:busi /home/user/ftp_1/IN/$line 2>>$log
done

echo "Rename files;" >> $log

/home/admin/bin/ren 's/\.txt$/.old/'>>$log 2>> $log
cd /ftpin/ffi
ftp -n -i $HOST >> $log 2>> $log <<END_fgSCRIPT
quote USER $USER
quote PASS $PASSWD
cd ..
cd ABC_FTP
cd IN
mput *.old

quit
END_fgSCRIPT
rm -f *.old
fi

ftp -n -i $HOST >> $log 2>> $log <<END_fgSCRIPT
quote USER $USER
quote PASS $PASSWD
cd ..
cd ABC_FTP
cd IN

mget $FILE1 2>>$log
mdelete $FILE1
quit
END_fgSCRIPT
cd /ftpin/ffi
ls *.TXT > $test 2>>/tmp/log
numline=`cat $test|wc -l`

if [ "$numline" -gt 0 ]; then
echo " Following files have been pulled from ftp server">>$log
cat getfile.test>>$log


cp /ftpin/fsi/*TXT /home/user/ftp_1/IN/ 2>> $log
exec < $test
while read line
do
chmod 666 /home/user/FTP_1/IN/$line 2>>$log
chown ftp_user:busi /home/user/FTP_1/IN/$line 2>>$log
done
echo "Rename files;" >> $log

/home/admin/bin/ren 's/\.TXT$/.old/'>> $log 2>> $log
cd /ftpin/ffi
ftp -n -i $HOST >> $log 2>> $log <<END_fgSCRIPT
quote USER $USER
quote PASS $PASSWD
cd ..
cd ABC_FTP
cd IN

mput *.old

quit
END_fgSCRIPT
rm -f *.old
fi


exit 0
 
Old 06-06-2006, 01:24 AM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
I haven't taken the time to go through your script yet, but is it vital that the script use standard ftp? If not, I would recommend grabbing a copy of ncftp. The command line options will make your life a lot easier.
 
Old 06-06-2006, 01:54 AM   #3
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
FILE=FILE='Myfile*2006'$DATE*
this way it cant work
u are trying to fetch or put
'File=Myfile20060504xy.mp3'

Last edited by j-ray; 06-06-2006 at 01:57 AM.
 
Old 06-06-2006, 03:38 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
why not use .netrc?
man netrc

you specify login details and it automates for you.
make sure you chmod 600 .netrc first.

you can have macros to do commands too,
something like this:
Code:
machine blah.com
user terrence
password letmein
macdef init
hash
bin
cd /pub
get file.txt
<blank line>
so if you
ftp blah.com it will log on and do the init macro
 
  


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
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
about shell scripting qrshat Programming 3 04-20-2006 09:22 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
shell scripting s_shenbaga Linux - Newbie 1 10-21-2005 04:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 PM.

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