Home

  Products   Downloads   FAQ  

Contact

     
     
 


FTP batch file example

FTP commands for batch files


You can run FTP commands in a batch file with the command

ftp -s:filename

Create a .txt file with the FTP commands, one command per line.

open <hostname>
<FTP user>
<FTP password>
hash                 # display progress
bin                  # copy in binary mode (or asc for Ascii)
bell                 # ring bell when download is finished
lcd <local folder>   # change local directory
cd <remote folder>   # change directory on FTP server
get <remote file>    # copy file to local directory
bye
      

Example FTP batch file download_logfiles.txt:

open www.mydomain.com
john
moNkey77
hash
asc
lcd c:\temp
cd statistics/logs
get access_log
bye

Now you can start the download from the command line with the following command:

ftp -s:download_logfiles.txt


How can I check port 21 (FTP)?

You can check TCP port 21 (and other ports) with the PortCheck.exe TCP port check command line tool. PortCheck is a free command line tool for Windows 7/8/10, no installation is required. It can be downloaded at www.portcheck-tool.com. You can use it like the Ping command:

portcheck MyFtpServer 21

or continuous

portcheck -t MyFtpServer 21

The result looks like this:


C:\Users\admin>portcheck -t ftp.myftp.com 21
ftp.myftp.com - Port 21 - OPEN - 30ms
ftp.myftp.com - Port 21 - OPEN - 34ms
ftp.myftp.com - Port 21 - OPEN - 40ms
ftp.myftp.com - Port 21 - OPEN - 50ms
ftp.myftp.com - Port 21 - OPEN - 47ms
ftp.myftp.com - Port 21 - OPEN - 30ms

ftp.myftp.com - Port 21 - closed
ftp.myftp.com - Port 21 - closed
ftp.myftp.com - Port 21 - closed
ftp.myftp.com - Port 21 - closed
ftp.myftp.com - Port 21 - closed

ftp.myftp.com - Port 21 - OPEN - 30ms
ftp.myftp.com - Port 21 - OPEN - 29ms
ftp.myftp.com - Port 21 - OPEN - 41ms
ftp.myftp.com - Port 21 - OPEN - 33ms
ftp.myftp.com - Port 21 - OPEN - 30ms
ftp.myftp.com - Port 21 - OPEN - 32ms
ftp.myftp.com - Port 21 - OPEN - 30ms
ftp.myftp.com - Port 21 - OPEN - 34ms
ftp.myftp.com - Port 21 - OPEN - 30ms
ftp.myftp.com - Port 21 - OPEN - 30ms


Another way to Check Port 25 (free tool)
Check the FTP port in regular intervals

If you would like to check your FTP Server at regular intervals, you can use the command line utility SLCheck. SLCheck connects to the FTP Server and checks the answer. Batch files can be executed in dependance of the result, e.g. to send alarm notifications. Try the following command:

SLCheck -p 21 -a ftp.domain.com -r "220 ProFTPD"

220 ProFTPD
can be the normal answer from a FTP Server.

All results are logged in a logfile. You can monitor your FTP Server by running SLCheck as a scheduled task, e.g. once a minute.

SLCheck Homepage

Content: FTP batch file commands Windows