Upload file to your FTP server from the Windows Command Line
Jul 8th, 2008 by dipankar
To automate FTP uploads from windows command line, first, you will have to create a batch file say fileup.bat in your windows directory, or at least inside some directory included in your path. You can use the “path” command to see what the current path is.
c:\>path
PATH=C:\WINDOWS;C:\WINDOWS\SYSTEM32;C:\;
Inside the batch file, you will want to paste the following:
@echo off
echo user UserName> ftpcmd.dat
echo Password>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat SERVERNAME.COM
del ftpcmd.dat
You have to replace the UserName, Password and SERVERNAME.COM with the correct values for your ftp server.
What this batch file is doing is scripting the ftp utility using the -s option for the command line utility.
The batch file uses the “echo” command to send text to the ftp server as if you had typed it. In the middle of the file you can add extra commands, like a change directory command:
echo cd /pathname/>>ftpcmd.dat
In order to upload the file named upload.zip to ftp, you have to call the batch file using the fileup.bat name that we gave it, and pass in the name of a file as the parameter. You don’t have to type the .bat part of the filename to make it work, either.
Example:
> fileup upload.zip
Connected to ftp.myserver.com.
220 Microsoft FTP Service
ftp> user username
331 Password required for username.
230 User username logged in.
ftp> bin
200 Type set to I.
ftp> put upload.zip
200 PORT command successful.
150 Opening BINARY mode data connection for upload.zip
226 Transfer complete.
ftp: 106 bytes sent in 0.01Seconds 7.07Kbytes/sec.
ftp> quit
And that’s all there is to it. Now your file should be sitting on the remote server. Enjoy…