Differences

This shows you the differences between the selected revisions of the page.

scripts 2008-01-31 scripts 2021-03-31 (current)
Line 1: Line 1:
====== Useful Scripts ====== ====== Useful Scripts ======
-===== [[upload]] Uploading single file ===== +··* [[script_upload_single_file|*]] 
- +  * [[script_upload_multiple_servers|*]] 
-Upload single file involves so little commands that it it enough to provide them on command line, saving writing a script file: +  * [[script_download_timestamped_filename|*]] 
- +  * [[script_download_most_recent_file|*]] 
-winscp.com user@example.com /command "put examplefile.txt /home/user/" "exit" +  * [[script_upload_most_recent_file|*]] 
- +  * [[script_checking_file_existence|*]] 
-===== Downloading file to timestamped-filename ===== +  * [[script_local_move_after_successful_upload|*]] 
- +  * [[script_locking_files_while_uploading|*]] 
-==== Using local-side scripting ==== +  * [[script_downloading_when_done_file_exists|*]] 
- +  * [[script_download_files_to_same_folder|*]] 
-You can use any available scripting language you have on the local host to generate appropriate WinSCP script. Following example uses PHP language: +  * [[script_upload_file_list|*]] 
- +  * [[script_synchronize_any_local_file|*]] 
-<code winscp> +  * [[script_auto_compress_download|*]] 
-get /home/user/examplefile.txt *.<?=date("YmdHis")?>.txt +  * [[script_custom_listing_format_csv|*]] 
-exit +  * [[script_retry|*]] 
-</code> +  * [[script_formatting_timestamp_batch_file|*]] 
- +  * [[script_email|*]] 
-When executed, the generated WinSCP script file may look like+  * [[script_vbnet_robust_example|*]]
- +
-<code winscp&gt; +
-get /home/user/examplefile.txt *.20060605090825.txt +
-exit +
-</code> +
- +
-Now pass the generated script file as input to WinSCP ((WinSCP [[scripting#console|console interface tool]] supports script on standard input since 3.8.2 only. With earlier versions you need to store the script into temporary file first.)): +
-<code> +
-php -q download.php | winscp.com user@example.com /script="%temp%\download.tmp" +
-</code> +
- +
-==== Using remote-side scripting ==== +
-If you do not have a scripting language on the local host, you can use remote-side script (like shell script). This approach requires opening separate [[shell session]] to invoke remote-side scripting. +
- +
-<code winscp> +
-# Make copy of the remote file to temporary timestamped file+
-# Also add unique extension to easily find the file in the temporary directory. +
-call cp /home/user/examplefile.txt /tmp/examplefile.`date +%Y%m%d%H%M%S`.unique +
-# Download all the files with the unique extension+
-# There should be only one, the one just created. +
-# While downloading, remove the unique extension. +
-get /tmp/*.unique *. +
-# Remove the temporary file. +
-rm /tmp/*.unique +
-exit +
-</code> +
- +
-===== Downloading the most recent file ====+
-The script below requires opening separate [[shell session]] to invoke remote-side scripting. +
- +
-<code winscp> +
-# Make copy of the most recent file using remote command to new name +
-# with unique extension to easily find the file in the temporary directory. +
-call cp `ls -t | head -1` /tmp/`ls -t | head -1`.latest +
-# Download all the files with the unique extension+
-# There should be only one, the one just created. +
-# While downloading, remove the unique extension. +
-get /tmp/*.latest *. +
-# Remove the temporary file. +
-rm /tmp/*.latest +
-exit +
-</code> +
- +
-===== [[local_move]] Moving local files to different location after upload ===== +
-WinSCP does not support move command for local files. Instead you can combine WinSCP script with batch file: +
- +
-&lt;code winscp> +
-# Make the script abort on any error +
-option batch abort +
-# Connect +
-open session +
-# Upload the files +
-put *.* +
-</code> +
- +
-Launch the above script from batch file like the one below+
- +
-<code> +
-winscp.com /script=example.txt +
-if errorlevel 1 goto error +
- +
-echo Upload succeeded, moving local files +
-move *.* c:\backup\ +
-exit +
- +
-:error +
-echo Upload failed, keeping local files +
-</code> +
- +
 +===== Other Examples =====
 +  * Guide to [[guide_automation|scripting/automation]];
 +  * Guide to [[guide_automation_advanced|advanced scripting]];
 +  * See [[library_examples|*]] for advanced tasks.

Last modified: by martin