Showing posts with label WinSCP. Show all posts
Showing posts with label WinSCP. Show all posts

Monday, June 26, 2023

How to upload files via WINSCP client using a batch file

To upload files using WinSCP client via a batch file, you can create a script using the WinSCP scripting language and then execute it using the WinSCP command-line interface (CLI). Here's an example of how to accomplish this:

  1. Create a text file with the extension .txt and open it with a text editor.

  2. Inside the text file, write the WinSCP script commands. Here's an example script that uploads a file to a remote server:

option batch abort
option confirm off
open sftp://username:password@example.com
put "C:\path\to\local\file.txt" "/path/on/remote/server/file.txt"
exit
  

Replace username, password, example.com with your actual server details. Modify the local and remote file paths as needed.

  1. Save the text file and change its extension to .script. For example, upload.script.

  2. Create a batch file (.bat or .cmd) with the following content:

@echo off
"C:\path\to\WinSCP\WinSCP.com" /script="C:\path\to\upload.script"
  

Replace C:\path\to\WinSCP\WinSCP.com with the actual path to your WinSCP executable.

  1. Save the batch file.

  2. Double-click the batch file to execute it. It will launch the WinSCP client and run the script, uploading the specified file to the remote server.

Make sure you have WinSCP installed and configured properly before running the batch file. Adjust the paths and commands according to your specific setup.