12

What are the FTP commands for uploading files to a server using the Windows command prompt?

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
DEVOPS
  • 223
  • 1
  • 2
  • 5

4 Answers4

12

Open Windows CMD, type ftp and these commands:

ftp> open 123.4.567.89
ftp> user ftp_username ftp_password
ftp> cd folder1/folder2
ftp> quote pasv
ftp> binary
ftp> send C:\uploadfile.txt
ftp> disconnect  
ftp> quit  
  • 123.4.567.89 is the IP of your FTP server
  • ftp_username is the username to login on your FTP server
  • ftp_password is the password to login on FTP server
  • folder1/folder2 is the path on your FTP server where your file should be uploaded to
  • C:\uploadfile.txt is the path to your local file which should be uploaded

Read more

nixda
  • 26,823
  • 17
  • 108
  • 156
  • I tried above and it works up to the send command, but when trying the "send" command, I am getting "425 Unable to build data connection: Connection refused". Turns out I had to use "quote pasv" to enter passive mode first. – Mathias Conradt Mar 10 '16 at 10:22
  • 1
    The `quote pasv` does not work! It switches only the *server* to the passive mode, but not the *client*. So it makes the problem even worse. See https://superuser.com/q/1034347/213663#1034499 – Martin Prikryl Jan 05 '22 at 06:34
6

While, in some cases, you can use the Windows command-line ftp.exe client, as the answer by @nixda shows (except for the quote pasv part, which is wrong), in most cases you cannot. The ftp.exe does not support a passive mode, what makes it useless nowadays, when connecting over Internet due to ubiquitous firewalls and NATs.

Also nowadays you better use FTPS (an encrypted variant of FTP), what is also not supported by ftp.exe.

You better use any 3rd party FTP command-line client. Most do support the passive mode and FTPS.

For example with WinSCP scripting, you can use a batch file like:

winscp.com /log=upload.log /command ^
    "open ftpes://username:password@ftp.example.com/" ^
    "put ""C:\local\path\file.dat"" ""/remote/path/file.dat""" ^
    "exit"

There's even a guide for converting Windows ftp.exe script to WinSCP script.

(I'm the author of WinSCP)

Martin Prikryl
  • 21,071
  • 9
  • 77
  • 157
3

Use the page Microsoft Windows Command-Line FTP Command List.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
0

I am sure there is better more professional ways to upload files+folders to a server in one go, but the fastest hack I have been using is to zip all my files and folders, uploading the zip file to dropbox then getting the dropbox link of the file which ends with "=0", I replace the end ZERO with ONE, then run wget URL-THAT-ENDS-WITH-ONE on the server terminal inside a folder I wanted to upload to. Then I rename the file so it ends with .zip extension, then unzip it.

Sam Shaba
  • 101