preloader
blog-post

How to run FTP script in windows command line / Task Scheduler

Table of Contents

Let’s say we need to FTP a file (say filename.txt) from my local windows machine/server (say C:\ftp\output) to a remote server (say remoteserver.com) using a windows script (say C:\ftp\scripts\FTPTest.dat). The reason why we could need a script is to automate the file transfer process. This is a basic approach which can be used when we don’t have enterprise level file transfer solutions.

  • Make sure you can access the remote server from your machine and there is no firewalls blocking them
  • Make sure the remote server accepts FTP connections.
  • Make sure you have a working user ID and password in the remote server.

Create the script and save the same

Create C:\ftp\scripts\FTPTest.dat and have the following commands in it, Make changes to server, user name, password and directories as applicable

!REM ===================================================================================  
!REM Description - FTP script to FTP a file  
!REM FILE - filename.txt  
!REM DEVELOPER - Siva Nadesan  
!REM
===================================================================================  
open remoteserver.com  
userid  
password  
lcd C:\\ftp\\output  
put filename.txt  
!del filename.txt  
ls  
bye  

Run the script from windows command prompt

ftp -s:C:\\ftp\\scripts\\FTPTest.dat > C:\\ftp\\logs\\FTPTest.log

For one time activity this should help, If you need this to be scheduled then save the command in a new file say C:\ftp\scripts\FTPTest.cmd and schedule the same to be executed from windows task scheduler.

ftp -s:C:\\ftp\\scripts\\FTPTest.dat > C:\\ftp\\logs\\FTPTest.log

Schedule in task scheduler

  • Open Task Scheduler
  • Action -> New Task, Name the task as applicable (say FTPTest)
  • Update the trigger tab with the schedule details
  • Update the action tab to add a new action and browse to the script you have created (Say C:\ftp\scripts\FTPTest.cmd)
  • Click okay and now you should see the task you have created in the Task Scheduler Library, Right click the task name and run it to make sure its running without any issues.
Share this blog:
Comments

Related Articles