Differences

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

library_example_download_clipboard 2016-06-07 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% -sessionLogPath "%SessionLogPath%" +# @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%" 
-# @version      2+# @description  Downloads remote file from a path stored in clipboard
 +#                  to the current local directory 
 +# @version      6
# @homepage    ~~SELF~~ # @homepage    ~~SELF~~
-# @require      WinSCP 5.8.4 +# @require      WinSCP 5.16 
-# @option      Pause pausecheckbox +# @option      Pause -config pausecheckbox 
-# @option      SessionLogPath sessionlogfile+# @option      SessionLogPath -config sessionlogfile
# @optionspage  ~~SELF~~#options # @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,     $sessionLogPath = $Null,
    [Switch]     [Switch]
-    $pause = $False+    $pause
) )
Line 56: Line 58:
        $session.Open($sessionOptions)         $session.Open($sessionOptions)
-        Write-Host ("Downloading {0}..." -f $remotePath)+        Write-Host "Downloading $remotePath..."
        $session.GetFiles($remotePath, (Join-Path $localPath "*")).Check()         $session.GetFiles($remotePath, (Join-Path $localPath "*")).Check()
    }     }
Line 68: 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 84: Line 86:
</code> </code>
-===== Options =====+===== [[options]] Options =====
The //Pause at the end// makes the script wait for a key press when it finishes. 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 //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