I need to upload a single file to FTP server from Ubuntu. This operation should be done in a script (in non-interactive mode). What is the right syntax for ftp?

I'm trying this, to no avail:

$ ftp -u ftp://user:secret@ftp.example.com my-local-file.txt
ftp: Invalid URL `ftp://'
link|improve this question

80% accept rate
How do I man page? – Ignacio Vazquez-Abrams Aug 15 '11 at 2:18
1  
What do you mean? – yegor256 Aug 15 '11 at 2:31
I don't know much about the ftp tool in Ubuntu, but it looks like it's choking on the ftp://. try taking that out maybe? – Nate Koppenhaver Aug 15 '11 at 4:15
feedback

migrated from serverfault.com Aug 15 '11 at 1:55

This question came from our site for system administrators and desktop support professionals.

3 Answers

up vote 5 down vote accepted

Here is one approach:

$ ftp -n <<EOF
open ftp.example.com
user user secret
put my-local-file.txt
EOF

Alternatively, create (or edit) the ~/.netrc file in the home dir of the user that will run the ftp command, give it appropriate perms (chmod 0600 ~/.netrc), and add the following:

# ~/.netrc
machine ftp.example.com
login user
password secret

Then omit the login information, as in:

$ echo put my-local-file.txt | ftp ftp.example.com

Also, here's how you might do the same thing using curl:

$ curl -T my-local-file.txt ftp://ftp.example.com --user user:secret
link|improve this answer
feedback

Install ncftp and use the ncftpput tool that comes along with it, pretty much something like this syntax:

ncftpput -Uftpuser -Pftppass ftphostname /path/where/to/upload localfile.name
if [ $? -ne 0 ]; then echo "Upload failed"; fi

You can even check if the upload status is good or bad. The normal ftp client can also be used along with expect.

link|improve this answer
feedback

You need to fix the URL given in your statement. You received the error because the URL was incomplete - it was missing the name of the object you are uploading. Once you add the filename after 'example.com' as I have done below, you will see the single command does indeed work as you intended.

Try this:

ftp -u ftp://user:secret@ftp.example.com/my-local-file.txt my-local-file.txt

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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