Monday, 6 November 2017

linux - How to upload one file by FTP from command line?


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://'

Answer



Here is one approach:


$ ftp -n <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

No comments:

Post a Comment

Where does Skype save my contact&#39;s avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...