ftp files inside a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ftp files inside a shell script
# 1  
Old 02-06-2006
ftp files inside a shell script

I have a shell script where I am trying to ftp some files but I get the error message "EOF unclosed" every time the script reaches the ftp section. Here is how my script is written.


#more code up here
rm -f $object >> $LOG_FILE 2>&1
fi #end of if
done #end of for loop

#################################################
ftp -n -v -i << EOF >> $LOG 2>&1
open $HOST_ADDRESS
user $HOST_LOGIN $HOST_PASSWD
ascii
lcd $DIR
cd $FTPDIR
mput $REPORT.*
close
quit
EOF
#################################################

This same script works if I take the FTP part and put it in a separate script by itself. But I don't like the idea of having a separate script just for FTP and would like to keep all of the code in the same script, if possible.

Please help on this issue as I am not sure what is wrong here.
# 2  
Old 02-06-2006
You could use functions in a shell script. I have a script where one function does the FTP and the rest is taken care by other functions. I suppose the same would work for you too.
# 3  
Old 02-07-2006
HI,
Did u try eot_ in place of EOF
# 4  
Old 02-07-2006
after ftp the file. bye is not closed

for example..
for i in `cat a`
do
ftp -i -n I.P <<EOF
user Login password
promp
hash
mput $i
bye
EOF
done

revert back whether ur prob solved or not
Narsing
# 5  
Old 02-07-2006
I have found cURL (command-line URL) indispensable for writing scripts with FTP commands. It is available at http://curl.haxx.se/ (both compiled binaries and source code).

It takes the place of the FTP client allowing not only puts and gets but deletes and directory listings. It also returns a detailed exit code for conditional evaluations.

For example, your original post could be handled with:

cd $DIR
for FILE in $REPORT.*
do
if curl -T $FILE -u $HOST_LOGIN:$HOST_PASSWD ftp://$HOST_ADDRESS/$FTPDIR/
then
echo "$FILE transferred"
else
echo "FTP of $FILE failed" 1>&2
fi
done

This is a simple example. It supports numerous protocols and has more options than letters in the alphabet. The usefulness of this utility in scripts is without measure.

Last edited by hegemaro; 02-07-2006 at 11:10 AM..
# 6  
Old 02-07-2006
Thanks for all the help. I was finally able to resolve this issue. There was a bad character after EOF in my code that I could not view through vi. After hours of troubleshooting I found this issue and deleting the character after EOF resolved the issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

FTP in shell script and selecting files for upload

Hi, Im a newbie with programming and shell scripting. Im running OSX/Mac and Darwin. I would like to create a shell script that would : 1. Search a Volume and directory (including subdirectories) for a file that : * filename ends with ”_Highres.pdf” and * the file creation date of... (8 Replies)
Discussion started by: NickeZ28
8 Replies

2. Shell Programming and Scripting

Shell FTP script to send all files to different path

Hello to all in forum I hope you can help me. I want to send via FTP to a linux server the 2 kind of files that are in the same folder, as follow: 1- Send all files that are named verified.SomeString.zz.pttp to path /var/verified 2- Send all files where the name begins with verified.conf... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

3. Shell Programming and Scripting

shell script to ftp multiple files

Hi, i use the below script to send a single file to remote server from linux. ftp -nvi <<!EOF open $Host_name user $USER_ID $PWD binary mput $file_name quit !EOF (where i... (2 Replies)
Discussion started by: pradebban
2 Replies

4. Emergency UNIX and Linux Support

Shell script to get all the files from FTP server

Hi Guru's, I am new to UNIX. my requirement is to log on to FTP server and get all the .txt files. i have developed one script by searching some forums but getting error and not able to fix them. pls see below code. ftp -i-n<<EOF open $FTP_HOST... (30 Replies)
Discussion started by: arund_01
30 Replies

5. UNIX for Dummies Questions & Answers

ftp files from one server to another using shell script

Hi Guys Any Help I have created a spool file that i need to copy onto another server using FTP in a shell script both servers are linux (3 Replies)
Discussion started by: itai
3 Replies

6. UNIX for Advanced & Expert Users

Shell script to ftp files from windows to unix

Hi , I need to ftp some input files from windows to unix server.All the files will be saved in the C drive in my machine.Currently all these files are transferring manually to the unix server.I need to write a shell script which ftp the files from windows to unix box.When I searched in the forum i... (1 Reply)
Discussion started by: kavithakuttyk
1 Replies

7. Shell Programming and Scripting

deleting files inside shell script - ( using find)

Hi, I am using the command find /apps/qualdb/gpcn/scripts/cab_outbound/archive -name 'z*' -mtime +28 -exec rm {} \; in unix command prompt for deleting the files in my unix system under the specfied folder. It was succesfull. But when i running this command inside a shell script name... (2 Replies)
Discussion started by: Jayaram.Nambura
2 Replies

8. Shell Programming and Scripting

How to use ftp commands inside shell script? Help please

Dears, I'm new in shell scripting and i need your help, i would like to know how can i create a script to ftp to a certain unix/linux machine/server IP address and get a file for example without user intervention? How can i force the script to use a certain username and password to access this... (4 Replies)
Discussion started by: Dendany83
4 Replies

9. Shell Programming and Scripting

Getting a list of files on an ftp, via shell script...

G'day, I was wanting to write a shell script that checks an ftp server for the presence of new files, then get those files. In so much as the get, this is pretty straight forward, but I cannot work out how to get a list of files to check. Is it possible for a shell script to get the output of... (1 Reply)
Discussion started by: Elric of Grans
1 Replies

10. Shell Programming and Scripting

Random files do not FTP in the shell script

The following script is used to loop through files in the /tmp directory and transfer those files onto another server. However, some of the files do not transfer. It is very random when the transferring is done (i.e. one of the files won't transfer then next time, that one will transfer and... (1 Reply)
Discussion started by: RLatham20
1 Replies
Login or Register to Ask a Question