Scheduling Transfer Files via FTP/SFTP use WinSCP

In some cases, your company needs to transfer several secret/sensitive data either to your customer/3rd party vendor. But, due to the routines and massive data which need to be delivered, there must be an operator to do such kind of task whereby this situation is really frustrating for them as supposed to be done via simple script which I’ll explain in next few words.

Also please bare in mind some security concern might be in place due to nowadays it is very not recommended for us to transmit something over internet without security header. It will lead your data into compromise by hacker and potentially will be misused.

Off to the topic.

In this case I’d like to explain a little bit about two components that we are going to use.

  1. FileZilla Server: this software allows you to activate file server feature over FTP/SFTP. You may configure in your file server located on the DMZ/Perimeter zone. Also just open the necessary port as requested and use the passive mode
  2. WinSCP: this is a software for FTP client; you can use to get/send the files to your FTP/SFTP server. I used to try with FileZilla client but unfortunately it doesn’t come up with scheduling feature that’s why I recommend this software instead

Ok, assuming that you’ve already had the FTP/SFTP server configured properly. If not, you may take a look charm trick to do here. So, now you need to install WinSCP on your laptop/pc. Once done, create a simple script .bat file as below:

@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\temp\log\winscp.log" /ini=nul ^
/command ^
"open ftpes://username:password@xxx.yourdomain.yyy:port/" ^
"put C:\temp\transfer /" ^
"exit"
del /s /q "C:\temp\transfer*.*"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%

Legend:
Username: put your username here which you’ve created on your FTP server
Password: put your password
xxx.yourdomain.yyy: target URL/IP of your FTP server
Port: what port that you are using for FTP communication
C:\temp\transfer“: location of the files that you desire to transfer

In addition above script will also delete once the transfer is completed. Then now you need to save above script and put with “.bat” extension file.

I’ve already put the script with filename: transfer_winscp.bat located on c:\temp and also some files on c:\temp\transfer

Let’s go to task scheduler and make a job schedule to transfer these files.

I created basic task with name: transfer files.

I chose daily and will always start on 10AM.

Select start a program and point to the script we’ve built.

See the recap and you are good to go.

An additional useful tips: if you want to run the script without any intervention and requires you to logon then you might need to activate above options.

Let’s start the schedule manually:

As seen above the script is working as expected and the files have been transferred successfully.

No more files left on the directory.

That’s all. Hope this information useful for you to setup proper script to transfer files automatically using FTP/SFTP server.

Leave a Reply

Your email address will not be published. Required fields are marked *