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:sec[email protected] my-local-file.txt
ftp: Invalid URL `ftp://'
  • 5
    How do I man page? Aug 15, 2011 at 2:18
  • 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? Aug 15, 2011 at 4:15
  • @IgnacioVazquez-Abrams man ftp at command line Mar 13, 2015 at 3:46
  • Similar: Syncronizing files over FTP, but for multiple files.
    – kenorb
    Apr 15, 2015 at 19:04
  • I'm getting '-u unknown option'. Aug 25, 2015 at 11:58

12 Answers 12


Here is one approach:

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

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
  • 1
    FYI: I've noticed that I can't pass a full path of the file using the put raw command but I can with curl.
    – Hengjie
    Jan 14, 2013 at 21:55
  • 2
    +1 for the curl. Neat, clean and straight to the point! In Debian/Ubuntu "apt-get install curl", if you don't have it.
    – GTodorov
    Mar 6, 2016 at 18:57
  • 5
    the curl solution is the best and the easiest
    – user512278
    Mar 28, 2016 at 16:40
  • 1
    FWIW: I tried this with a large file (162MB). At first I thought curl looked slow (~25mins), but I found that the ftp command took just as long. curl looks good if available, and has nice feedback showing Time Left etc.
    – xtempore
    May 5, 2016 at 3:58
  • 3
    For uploads to a specific folder put a slash after the folder name: ftp://ftp.example.com/myFolder/ otherwise youl'll get "Failed FTP upload: 553"
    – Pino
    Jun 3, 2020 at 13:17

I can recommend ftp-upload. It's a neat little tool that you can install under ubuntu through sudo apt-get install ftp-upload.

Usage example:

ftp-upload -h {HOST} -u {USERNAME} --password {PASSWORD} -d {SERVER_DIRECTORY} {FILE_TO_UPLOAD}
  • Can you provide a link to the tool or its documentation?
    – bwDraco
    Jan 27, 2015 at 16:11
  • 1
    Hi DragonLord, if you are in Ubuntu and you have installed ftp-upload (using the command I gave before) you can just do man ftp-upload. Hope that helps.
    – Floris
    Feb 3, 2015 at 18:01
  • Will this leave the password in the bash history? Can I prevent that?
    – Xanlantos
    Feb 3, 2021 at 11:09
  • @Xanlantos yes unfortunately it will leave the password in the bash history. I think there are ways around it I found through Google (but I don't recall exactly).
    – Floris
    Feb 5, 2021 at 20:51

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:[email protected]/my-local-file.txt my-local-file.txt

  • 13
    ftp: invalid option -- 'u' Aug 1, 2014 at 17:06
  • 2
    Indeed :( ftp: u: unknown option Oct 28, 2014 at 10:24
  • ftp: u: unknown option
    – Morten
    Nov 8, 2018 at 11:45
  • perhaps it's version dependant, like nc -e flag. my ftp command has the -u and following this format, it worked nicely! Oct 28, 2022 at 22:05
  • Ah I just figured one thing out: this is because my ftp command is, actually, tnftp. You may want to check what FTP client you're actually using, since they'll have different capabilities! Nov 15, 2022 at 16:10

You can also try lftp.

Here is an example:

lftp -e 'cd folder1/folder2; put /home/path/yourfile.tar; bye' -u user,password ftp.theserver.com

Refer here for more details and also refer to LFTP Manual


  • To use it with non unix name I found this: NN="'non unix.file'" ; lftp -e "cd folder; put $NN; bye" -u anonymous, ftp.theserver.com
    – schweik
    Jan 17, 2020 at 8:22
  • 1
    Will this leave the password in the bash history? Can I prevent that?
    – Xanlantos
    Feb 3, 2021 at 11:09
  • 1
    With the example above yes, it will be in the history. You can use the --env-password flag and have the password configured in LFTP_PASSWORD environment variable. Refer to the man pages of LFTP Feb 4, 2021 at 15:41

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

ncftpput -u ftpuser -p ftppass 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.


Upload a file to a remote location via command line

#$1 is the file name
#usage:this_script <filename>

quote USER $USER
put $FILE 
exit 0

I use BusyBox's ftpput to do this:

# /bin/busybox ftpput

BusyBox v1.20.2 (Debian 1:1.20.0-7) multi-call binary.


Upload a file to a FTP server

    -v,--verbose            Verbose
    -u,--username USER      Username
    -p,--password PASS      Password
    -P,--port NUM           Port

Note: busybox ftpget work well too.


Use the put command after connecting to the FTP server with ftp (it is interactive, btw).

put local-file [remote-file]
             Store a local file on the remote machine.  If remote-file is left unspecified, the local file name is used after processing according to any ntrans or nmap settings in
             naming the remote file.  File transfer uses the current settings for type, format, mode, and structure.

Example login:

~ $ ftp
Connected to
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 1 of 25 allowed.
220-Local time is now 10:47. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Name ( user2
331 User user2 OK. Password required
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.

Example copy (login required before it):

ftp> put index.html
local: index.html remote: index.html
200 PORT command successful
150 Connecting to port 43791
226-File successfully transferred
226 0.003 seconds (measured here), 3.96 Mbytes per second
10701 bytes sent in 0.00 secs (34.4773 MB/s)

Example logout (login required before it)

ftp> quit
221-Goodbye. You uploaded 11 and downloaded 0 kbytes.
221 Logout.
~ $

You could also use the sftp or ftp command

sftp {user}@{IP}
put {path To File On Local Computer}


i improved Marty answer like below (include binary):


$ ftp_example_sh.sh dump_file

ftp -n <<EOF
user anonymous aaa
put $1


$ftp_example_2.sh dump_file

ftp -n <<EOF
open $1
user anonymous aaa
put $2

With curl:

curl -T $file -u "$user:$pass" ftp://xxxxx.xxx[:$port]/server/path [--ftp-ssl] [-k]

Between braces are optionals

  • Welcome to Super User! Before answering an old question having an accepted answer (look for green ✓) as well as other answers ensure your answer adds something new or is otherwise helpful in relation to them. Here is a guide on How to Answer. There is also a site tour and a help center. Sep 16, 2022 at 18:49
    echo `echo -e "open host\nuser user pass\nbinary\nput $1\nquit"|ftp -nv`
FtpPut asd.txt
FtpPut asd.mp4
FtpPut asd.php

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .