Linux FTP upload: "No such file or directory", but file exists

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?


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.


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