8/3/2021
20
Documentation » Using WinSCP » Guides » Scripting/Automation »

This guide contains a simplified description of automating operations on FTP/SFTP server with WinSCP. You may want to see detailed documentation of the scripting functionality instead.

FTP Task / Script Task SSIS Video Scenario:A vendor put multiple files in FTP Server on designated folder for us to download. We want to build a process in w. Allowing full automation of FTP/SFTP transfers, the tool can execute commands on local and remote PCs, and perform FTP commands, batch files, and scripts. The support of local and remote commands allows automatically compressing (tar+gzip), transferring, and unpacking a bunch of files and directories completely automatically. Total Commander has built-in functionality for FTP and synchronization. Just download and install it, connect to the FTP folder in the left pane, open local folder on the right, and choose Commands - Synchronize Dirs. Hi Friends, I want to sync my local folder with some FTP server. My client sent me some 800 GB data by FTP, which I have downloaded. Now he is adding,removing & updating some files, so it's difficult for me to identify the changes & download the modified files. ' Get file list of Local folder LocalFolderFiles = Directory.GetFiles(LocalFolder) ' Get list of FTP subfolders and files ftp.GetListing(StrFolderArray, StrFilesArray) ' Synchronize content of the remote folder to the local folder ' If the remote folder have subfolders If Not (StrFolderArray Is Nothing) Then For Each SubFolderName In StrFolderArray.

WinSCP offers scripting interface that you can use to automate many operations that it supports, including file transfers, synchronization and other operations.

There is also WinSCP .NET assembly built on top of the scripting interface. If you plan to call WinSCP from your .NET code or PowerShell, or if your task requires conditional processing, loops or other control structures, you should better use the .NET assembly. This guide focuses on simple automation tasks using scripting interface only.

Before starting you should:

  • Have WinSCP installed;
  • Know how to connect to your FTP/SFTP account.

To automate operation, you need to find out commands necessary to implement it. For simple operations you need at least to:

  • Open session using open command.
  • Perform operation. For uploads use put command. For downloads use get command. For synchronization use synchronize command. For other operations, see supported commands.
  • Exit scripting using exit command.

For example a typical script to upload a file is:

Blue is the warmest color book free download

Assemble the commands into a script file. You can name the script file as you like. See simple example and some useful scripts.

Use the /scriptcommand line option to pass the script to the WinSCP executable. Generally, you should also use /ini=nul switch to isolate the script execution from GUI configuration. You can embed the complete command line into a Windows batch file (.bat), like as follows:

Advertisement

You can have WinSCP generate a script template for you or even a complete batch file.

To generate a script for a file transfer:

  • Connect in the GUI.
  • Select the files you want to transfer.
  • Use one of the file transfer commands: Upload, Download, Upload and Delete, Download and Delete.
  • On the transfer confirmation dialog, setup transfer options (if you need any non default settings).
  • Use the Transfer Settings > Generate Code command.
  • The Generate transfer code dialog will appear with the generated script or code template.

Now to make using script easier/automatic you can:

  • Make shortcut to it on desktop to ease execution. Either make shortcut to batch file (.bat) or enter full command line to shortcut itself.1
  • If the wrapping batch file takes filename as command line parameter (see below) you can:
    • Make shortcut to it on desktop and use it by dropping files on the icon. Windows automatically run the batch file and passes path to dropped file as command-line parameter.
    • In a similar way you can put the shortcut to the batch file into Explorer’s ‘Send To’ context menu (C:UsersusernameAppDataRoamingMicrosoftWindowsSendTo in Windows Vista and newer).
  • Schedule automatic execution.

When connecting to SSH host, you will need to accept its host key.

When connecting to FTPS or WebDAVS host with certificate signed by untrusted authority you will need to verify the certificate.

You may want to modify the script automatically. For example you may want to operate it with different file each time.

For tasks involving more complex modifications, conditional processing, loops or other control structures, you should better use the WinSCP .NET assembly.

For simple modifications, you can pass the variable parts of the script from command line:

Execute the above script using syntax:

You can also use environment variables in the script.

Alternatively, you can generate new script file each time. To automate that, make a wrapper script file. For simple tasks you can use built-in Windows scripting functionality from batch file (.bat). For complex tasks, you will need to use some scripting language, such JScript or VBScript from Windows script host or PHP or Perl.

Following example shows batch file that takes filename on command line and generates WinSCP script file to upload that file to remote server:

Now you can run the batch file like (supposing you have saved it to file upload.bat):

See more hints on using parametrized batch file.

See Advanced FTP/SFTP scripting for examples of script generation using more powerful languages.

To check results of the script you can:

  • Check exit code of WinSCP (exit code is the only relevant and reliable way to check if script completed successfully). See example below and FAQ.
  • Save and inspect log file. XML log format is recommended. Use command-line parameter /xmllog.
  • Save and inspect output of the script. Use output redirection.

Once you find out what was the result of the script, you can perform any action you like: print a message, send an email, etc.

You should also make the batch file indicate a result in its exit code, particularly if it is called from some parent system (for example SSIS).

See an example batch file:

Auto Sync Ftp Folder With Local Folder Mac

A similar error handling is used in the batch file template that WinSCP can generate for you.

If you require checking results of each command individually, you should better use the WinSCP .NET assembly. Alternatively, see the guide Advanced FTP/SFTP scripting for examples of checking script results (including XML log parsing) using more powerful languages and the guide to Interpreting XML log for advanced scripting using C# language.

See example in scripting documentation.

  • Troubleshooting;
  • Scripting documentation;
  • Guide to Advanced FTP/SFTP scripting;
  • WinSCP .NET assembly and COM library;
  • Command-line parameters;
  • WinSCP executables;
  • FAQ about scripting;
  • Example scripts;
  • Schedule file transfers (or synchronization) to FTP/SFTP server.

Advertisement

  1. Note that it is not possible to use winscp.com (.com files in general) directly from a shortcut. Call winscp.com from a batch file or use winscp.exe with /console command-line parameter.Back

FTP sync allows making two folders on some FTP servers identical. This can be a correction for one folder according to another (the “master-slave” relations), or just copying actual versions of files and subfolders between FTP sync folders (mirroring). Handy Backup can do it automatically!

Crucial Features of FTP File Synchronization

Automatic FTP Sync by Time or Events

By using Handy Backup, you can schedule automated tasks for FTP sync to an exact time and exactly defined repeating period, from several months to a single minute. You can also trigger an FTP synchronizer task by some system event such as user logon or unlocking a computer.

Local

Controlling Synchronization by GUI or Remotely

View

Besides a convenient, modern-looking graphical user interface (GUI) to create and control any file sync task, Handy Backup allows notifying and reporting about any task by email, starting in a command-line mode for batch jobб or running “silently” as Windows service to make no distraction during FTP sync.

Cross-platform Solution

Handy Backup allows not only FTP sync Windows folders but can serve under any other OS for this purpose. Actually, it makes no differences between FTP servers, regardless of basic OS. Moreover, it supports both Windows and Linux as a software solution, and you can run it under Linux natively!

Supporting Protected FTP Protocols

Along with standard FTP, Handy Backup supports SFTP and FTPS protocols, with internal engines of traffic encryption. For practical purposes, it has no matter that an FTP sync folder is actually an SFTP or FTPS folder. Handy Backup will transfer files between all these servers with no restriction!

Ftp folder view

Recommended Solution

DownloadCompare

Version 8.2.3, built on March 29, 2021 . 111 MB
Backup Software from Novosoft LLC. 89USD per license.

Handy Backup Professional

The Professional edition allows FTP sync between any types of file servers out of the box, with all features and functions of Handy Backup!

How to Make Automatic FTP Sync Task in Handy Backup?

To create a task for FTP file synchronization between two sources, please follow next steps.

  1. Open Handy Backup. Run a New Task Wizard by clicking the “Create” button on the main control panel.
  2. On Step 1, select Sync. Do not mark the “Use Advanced Wizard” checkbox for now; we are creating a simple task.
  3. On the left panel, click onto a plug-in name to select a first folder, to choose a local folder, click FTP, SFTP or FTPS.
  1. On the right pane, click “Create a connection…” to enter the connection setup dialog.
  2. Enter your FTP server connection parameters, give a name for your connection, and then click OK.

Caveat! Connection setup is slightly different for FTP, SFTP and FTPS servers! Please learn more about FTP configuration, SFTP configuration or FTPS configuration.

  1. On the right panel, click onto your new connection name. Choose an FTP sync folder, and then click OK, followed by clicking Next.
  2. On Step 3, select a second folder by repeating pp. 3-6 for a second FTP sync folder.
  3. Go to Step 4 and select the direction (i.e. the method of governing FTP sync files). You can copy a first folder to a second folder, or second to first, or mirror the two folders content together.
Auto Sync Ftp Folder With Local Folder
  1. On this step, you can also select what to do with identical filenames in the two folders: copy or skip.
  2. The next step allows scheduling your task. If you want to start a task repeatedly, mark the “Enable scheduler” checkbox.
  3. Now you can select starting time and a repeating period for a task. Set up these parameters and click Next.
  4. This is a final step of the Task Creation Wizard. Give a name to your task.

Some Interesting Facts about FTP Sync

Ftp Folder Windows

  • Automatic FTP sync is a perfect method of kiosking (sending by subscription) some files and folders to remote users.
  • Also, using FTP sync files is a good choice for making mirrors of static website data (such as photos, codes or documents), as well as for keeping websites in actual state.
  • Because Handy Backup preserves native formats of any files during working as an FTP synchronizer, you can use file synchronization just for uploading and downloading workfiles.

Version 8.2.3, built on March 29, 2021
111 MB

Try FTP file synchronization with Handy Backup just now! Download a 30-day free trial version!

Auto Sync Ftp Folder With Local Folder Windows 10

6817.info – 2018