Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to upload backup archives from one server to another server using ftp. In my backup cronjob I use this script to upload files:

MEDIAFILE=/var/somedir/somefile.encrypted
if [ -r $MEDIAFILE ]
# File seems to exist and is readable
then
ftp -n $FTPHOST <<END_SCRIPT
quote USER $FTPUSER
quote PASS $FTPPASS
cd backups
put $MEDIAFILE
quit
END_SCRIPT
fi

This script returns:/var/somedir/somefile.encrypted: No such file or directory. But the file exists and the user executing the script has rights to read the file.

What is causing this error?

share|improve this question
    
Try (Line 1): MEDIAFILE="/var/somedir/somefile.encrypted" –  cyberx86 Jul 5 '11 at 19:34
    
I already tried that and it didn't make a difference. Thanks anyway. –  i.amniels Jul 5 '11 at 19:41
    
What shell and what flavour of Linux? (Might not be needed, but I am used to bash/CentOS). –  cyberx86 Jul 5 '11 at 19:44
    
@cyberx86 Debian and I use /bin/sh –  i.amniels Jul 5 '11 at 19:48
    
No spaces beside your equal sign, no dollar sign for variable assignment, and quoted string - and I don't get the error (on sh). Without quotes I get the error, and other errors for the other scenarios. I might suggest trying it as a basic if then ... else .. fi statement and seeing if that works - put an echo in each section. –  cyberx86 Jul 5 '11 at 19:55

2 Answers 2

up vote 5 down vote accepted

Alright, I should have done this to start with:

FTPHOST="domain.com"
FTPUSER="xxxxxx"
FTPPASS="xxxxxxxxx"
MEDIAFILE=/path/to/something.enc
if [ -r $MEDIAFILE ]
# File seems to exist and is readable
then
ftp -n $FTPHOST <<END_SCRIPT
quote USER $FTPUSER
quote PASS $FTPPASS
cd backups
bin
put $MEDIAFILE something.enc
quit
END_SCRIPT
fi

I added the remote filename to put, and the bin command - tested and works - hopefully it helps.

Edit: I should explain - the put command will assume that the remote path is the same as the local path if a remote path is not specified (second parameter) - so without the remote path, the file was not found on the remote server.

share|improve this answer
    
Thanks a lot for all the effort you have put in this solution! :) –  i.amniels Jul 5 '11 at 22:00

Dollar sign shouldn't be used when assigning value to a variable. So try this code:

MEDIAFILE="/var/somedir/somefile.encrypted"
if [ -r $MEDIAFILE ]; # File seems to exist and is readable
then
ftp -n $FTPHOST <<END_SCRIPT
quote USER $FTPUSER
quote PASS $FTPPASS
cd backups
put $MEDIAFILE
quit
END_SCRIPT
fi
share|improve this answer
    
Oops, the dollar is a copy/paste error and is not in the real script, I edited my original message. Tnx for pointing out and for all the effort. –  i.amniels Jul 5 '11 at 20:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.