简体   繁体   中英

FTP Shell Script Not Working

Ok, So I am trying to ftp some recording files to remote a server for backup every night. I am very confused regarding shell script. My question / problem is : I want to move to remote a server the whole folder/directory instead of FILE. Where am I wrong?

Here is current script:

HOST='10.113.68.50'
USER='sms'
PASSWD='Abc123451'
LOCALPATH='kmpy/unica/Campaign/partitions/partition1/CiktiDosyalari'
FILE=*.sms
DIR='SMS/'

ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
cd $DIR
lcd $LOCALPATH
put $FILE
quit
exit;
EOF

The ftp put command can only be used with a single file. If your *.sms expands to more than that, it will copy the first file across, and give it the name of the second file in your list. You should use the mput command instead, or tar everything into one archive, transfer that, and then untar it at the other end.

I take it that you only receive one file? For 'ftp' to use file globbing you need to use the 'mput' command. Replace put $FILE with:

prompt
mput $FILE

You need the 'prompt' command to turn off interactivity, and 'mput' will put multiple files.

However, 'ftp' might not be the best tool for the job. I would recommend using 'rsync'. The task above can be done with:

HOST='10.113.68.50'
USER='sms'
RSYNC_PASSWORD='Abc123451'
LOCALPATH='kmpy/unica/Campaign/partitions/partition1/CiktiDosyalari'
FILE=*.sms
DIR='SMS/'

rsync -avz $(LOCALPATH)/$(FILE) $(USER)@$(HOST):$(DIR)

'rsync' will only transfer the changes in the files and compress the transfer.

EDIT: Typically 'rsync' uses 'ssh' by default for authentication. If you want to use the 'rsh' method (which is the same as for 'ftp') you should do something like:

rsync -avz --rsh=rsh $(LOCALPATH)/$(FILE) $(USER)@$(HOST):$(DIR)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM