May 6, 2017

f Comment

Unix: How to fix FTP "Cannot create file" error?

Amazon When you run a shell script on Unix to send a file to a remote machine via FTP, your shell script may look something like this:

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
binary
put /some/where/else/someFile.tgz
quit
END_SCRIPT

But when you run the script, it reports an error like this:

someFile.tgz: Cannot create file.

How do you fix this error so that you can FTP a file to a remote host?

Solution

The problem is the file you want to transfer must reside in the current directory. In other words, you cannot have:

put /some/where/else/someFile.tgz

You must have:

put someFile.tgz

To be honest I am not sure why, but this fix solved the problem for me.

If you run a cron job, it runs in your home directory, which is the directory the command "cd" takes you to.

If the file you get on the remote host is corrupt, make sure you have the keyword "binary" right after "PASS" command.

Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael