Batch Upload Worpdress Users Then Send a Temporary Password
Question: I accept been running cron on a Linux server to take a fill-in of my website once in a day. Simply I download those backups to my local automobile (which is Windows) once in a week or so. Is information technology possible to automate file transfer from Linux to Windows?
Answer:
Yes, you tin. Accept a wait at WinSCP'south Scripting and Automation feature.
In this tutorial, I'll exist explaining how to write a batch script to automate file transfer between Linux and Windows using WinSCP and then schedule the script using Job Scheduler in Windows.
Assumptions: I assume that the SSH server is running on a Linux machine and the local machine is Windows ten.
Writing Batch Script to Automate File Transfer from Linux to Windows
Did I say writing a batch script? I didn't mean really, instead we will be using WinSCP to generate the batch script.
Step one: Launch WinSCP awarding.
Step 2: First of all, cheque the version of WinSCP
Step 3: If you lot are using a older version of WinSCP, then y'all need to download and install the latest version.
Step iv: Launch WinSCP afterward installing the latest version.
Stride five: Login to Linux machine (remote) past enter the necessary details such as IP accost, username and password.
Step half dozen: Upon successful login, click Session > Generate Session URL/Code from the carte du jour.
Step seven: In the " Generate Session URL/code " dialog, spotter for "Countersign" check box. If it'south disabled, y'all need to enable it for automating the file transfer. To do that, you demand to salve the session with necessary username and password.
Circumspection: It's non advised to salvage the countersign, but if you want to automatically login and transfer files, so you lot need to relieve the password.
Stride 8: Select " Script " tab and select " Batch file " in Format field.
Stride 9: Click " Copy to Clipboard " push and paste the code in a notepad.
Step 10: Alter the line "Your control 1" and "Your command 2". The commands can be get, put or synchronize .
For example, if you desire to put/upload a file to the remote directory, and then the command goes as beneath:
Put Syntax:
put <file> [ [ <file2> ... ] <directory>/[ <newname> ] ]
Put command examples:
put file.html
put d:\www\file.html
Get command examples:
get file.html d:\www\
If you desire to synchronize the folders between the remote and local machine, then you need to use synchronize local/remote/both commands. The below script shows that.
@echo off "C:\Program Files (x86)\WinSCP\WinSCP.com" ^ /log="Eastward:\Backup\WinSCP.log" /ini=nul ^ /command ^ "open up sftp://username:password@domain.com/ -hostkey=""ssh-rsa 2048 leave_the_key"" -rawsettings Cipher=""aes,blowfish,3des,chacha20,WARN,arcfour,des"" KEX=""ecdh,dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN""" ^ "synchronize local Eastward:\Backup /home/domain/backup" ^ "get out" set WINSCP_RESULT=%ERRORLEVEL% if %WINSCP_RESULT% equ 0 ( echo Success ) else ( echo Error ) exit /b %WINSCP_RESULT
In the above script, I accept used synchronize local to sync files between the remote and local machine. Information technology means, the changes in remote directory volition be practical to the local directory.
Annotation: The carrot ( ^ ) is used to split long commands.
Alternatively, y'all can use
- synchronize remote – the changes from the local directory are practical to the remote directory.
- synchronize both – will modify both the remote and local directories.
Step 11: Save the script as .bat (BATCH) file.
Step 12: Double click on the batch file to exam the script. You should see a command window displaying the status of file transfer.
Create task in Windows Task Scheduler
Finally, nosotros'll schedule the batch script using Windows task scheduler. Probably, you desire to schedule a fill-in at 3 AM everyday or every Monday.
Stride one: Launch Task scheduler program
Stride 2: From the menu click Activeness > Create Task
Step three: Prepare Name of the job, Triggers, Action and Weather condition as shown below:
Step 4: Verify if the chore has been created properly. To practise that, you need to click on "Task Scheduler Library" node from the left side panel and view the listing of job on the eye console.
Step 5: To exam the script, just right click on the task and select "Run".
If you want to take a backup of the task, and then correct click on the job and select Export.
Source: https://techglimpse.com/batch-script-automate-file-transfer-winscp/