Differences

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

library_example_download_clipboard 2016-05-30 library_example_download_clipboard 2022-06-16 (current)
Line 5: Line 5:
The script downloads a file or directory pointed to by a path in clipboard to a local directory. The script downloads a file or directory pointed to by a path in clipboard to a local directory.
-//In the latest beta version//, you can install this script as a [[extension|WinSCP extension]] by using this page URL in the //[[ui_pref_commands#extensions|Add Extension]]// command. &beta The extension will automatically use the current local working directory as a target.+You can install this script as an [[extension|WinSCP extension]] by using this page URL in the //[[ui_pref_commands#extensions|Add Extension]]// command. The extension will automatically use the current local working directory as a target.
<code powershell - DownloadClipboard.ps1> <code powershell - DownloadClipboard.ps1>
-# @name        &Download from Path in &Clipboard... +# @name        &Download from Path in &Clipboard 
-# @command      powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" -sessionUrl "!S" -localPath "!\" %Pause% +# @command      powershell.exe -ExecutionPolicy Bypass -STA -File "%EXTENSION_PATH%"
-# @description  Downloads remote file from a path stored in clipboard to the current local directory +#                  -sessionUrl "!E" -localPath "!\" %Pause% -sessionLogPath "%SessionLogPath%" 
-# @option ······Pause checkbox &quot;&amp;Pause at the end&quot; -pause -pause +# @description  Downloads remote file from a path stored in clipboard
-# @version ·····1+#                  to the current local directory 
 +# @version ·····
 +# @homepage ····~~SELF~~ 
 +# @require     WinSCP 5.16 
 +# @option      Pause -config pausecheckbox 
 +# @option      SessionLogPath -config sessionlogfile 
 +# @optionspage ~~SELF~~#options
param ( param (
-    # Use Generate URL function to obtain a value for -sessionUrl parameter. +    # Use Generate Session URL function to obtain a value for -sessionUrl parameter. 
-    $sessionUrl = "sftp://user:mypassword;fingerprint=ssh-rsa-xx-xx-xx@example.com/", +    $sessionUrl = "sftp://user:mypassword;fingerprint=ssh-rsa-xxxxxxxxxxx...@example.com/", 
-    [Parameter(Mandatory)]+    [Parameter(Mandatory = $True)]
    $localPath,     $localPath,
 +    $sessionLogPath = $Null,
    [Switch]     [Switch]
-    $pause = $False+    $pause
) )
Line 45: Line 52:
    try     try
    {     {
 +        $session.SessionLogPath = $sessionLogPath
 +
        Write-Host "Connecting..."         Write-Host "Connecting..."
        # Connect         # Connect
        $session.Open($sessionOptions)         $session.Open($sessionOptions)
-        Write-Host ("Downloading {0}..." -f $remotePath) +        Write-Host "Downloading $remotePath..." 
-        $session.GetFiles($remotePath, $localPath + "\*").Check()+        $session.GetFiles($remotePath, (Join-Path $localPath "*")).Check()
    }     }
    finally     finally
Line 61: Line 70:
    $result = 0     $result = 0
} }
-catch [Exception]+catch
{ {
-    Write-Host ("Error: {0}" -f $_.Exception.Message)+    Write-Host "Error: $($_.Exception.Message)"
    $result = 1     $result = 1
} }
Line 76: Line 85:
exit $result exit $result
</code> </code>
 +
 +===== [[options]] Options =====
 +The //Pause at the end// makes the script wait for a key press when it finishes.
 +
 +In the //Session log file//, you can specify a path to a [[logging|session log file]].
 +
 +In the //Keyboard shortcut//, you can specify a [[custom_key_shortcuts|keyboard shortcut]] for the extension.

Last modified: by martin