Copy Latest Files to Another Location Using FTP WinSCP Script
In this blog, Today we will create a script that will help us to copy latest files from FTP server and paste it to another server (FTP client server) using WinSCP Script. So, lets start the process.
Step 1: For this, We first need to install WinSCP on our clinet server. To install WinSCP, Please click on the link.
Step 2: After installing the WinSCP, Open the WinSCP GUI and connect your FTP/SFTP server using your credentials.
Step 3: Once you login to your FTP/SFTP server, go to Session -->> Generate Session URL/Code....
Step 4: Now, Copy the connection code and paste it on your notepad.
Step 5: Now, Lets start the scripting:
- First, create a get-latest-file.txt file and paste the below code in it:
1option batch abort
2option confirm off
3open ftp://<user>:<password>@<hostname>
4get -filemask="*>=1D" Source-Path Destination-Path
5exit
In 3rd line you have to paste your connection code, which you have copied earlier.
Default Source-Path is /* and Destination-Path is where you want to store the files. like
1get -filemask="*>=1D" /* c:\test-ftp\
- Second, create a bat file which will RUN the above script. Lets call it get-latest-file.bat and paste the below code in it:
1WinSCP.com /script=get-latest-files.txt
2pause
Note: When you add the below script in Windows scheduler for automate this. Remove the Pause syntax from the script.
Step 6 : Lastly move the both scripts to WinSCP installation directory. (C:\Program Files (x86)\WinSCP)
Step 7: Now, Run get-latest-file.bat file and your file will be uploaded to destination folder.