Differences

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

library_example_zip_and_upload 2018-07-30 library_example_zip_and_upload 2024-05-27 (current)
Line 12: Line 12:
<code> <code>
-powershell.exe -File "ZipUpload.ps1" -sessionUrl "sftp://username:password@example.com/" -remotePath "/remote/path" -archiveName "archive.zip" file1.dat file2.dat+powershell.exe -File "ZipUpload.ps1" -sessionUrl "sftp://username:password;fingerprint=ssh-rsa-xxxxxxxxxxx...@example.com/" -remotePath "/remote/path" -archiveName "archive.zip" file1.dat file2.dat
</code> </code>
 +
 +For opposite functionality, use extension [[extension_archive_and_download|*]].
<code powershell - ZipUpload.ps1> <code powershell - ZipUpload.ps1>
# @name        &ZIP and Upload... # @name        &ZIP and Upload...
# @command      powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" ^ # @command      powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" ^
-#                  -sessionUrl "!S" -remotePath "!/" -archiveName "%ArchiveName%" -pause+#                  -sessionUrl "!E" -remotePath "!/" -archiveName "%ArchiveName%" ^ 
-#                  -sessionLogPath "%SessionLogPath%" %Use7zip% -path7zip "%Path7zip%" +#                  -refresh -pause -sessionLogPath "%SessionLogPath%"
-#                  -archive7zip %Archive7zip% !&+#                  %Use7zip% -path7zip "%Path7zip%" -archive7zip %Archive7zip% !&
# @description  Packs the selected files to a ZIP archive and uploads it # @description  Packs the selected files to a ZIP archive and uploads it
# @flag        ApplyToDirectories # @flag        ApplyToDirectories
-# @version      6+# @version      10
# @homepage    ~~SELF~~ # @homepage    ~~SELF~~
-# @require      WinSCP 5.13+# @require      WinSCP 5.16
# @require      .NET 4.5 # @require      .NET 4.5
# @option      ArchiveName -run textbox "&Archive name:" "archive" # @option      ArchiveName -run textbox "&Archive name:" "archive"
Line 40: Line 42:
param ( param (
    # Use Generate Session 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 = $True)]     [Parameter(Mandatory = $True)]
    $remotePath,     $remotePath,
    [Switch]     [Switch]
    $pause,     $pause,
 +    [Switch]
 +    $refresh,
    [Switch]     [Switch]
    $use7Zip,     $use7Zip,
Line 108: Line 112:
        {         {
            $parentPath = Split-Path -Parent (Resolve-Path $localPath)             $parentPath = Split-Path -Parent (Resolve-Path $localPath)
 +            if ($parentPath[-1] -ne "\")
 +            {
 +                $parentPath += "\";
 +            }
            if (Test-Path $localPath -PathType Leaf)             if (Test-Path $localPath -PathType Leaf)
Line 122: Line 130:
            foreach ($file in $files)             foreach ($file in $files)
            {             {
-                $entryName = $file.Replace(($parentPath + "\"), "")+                $entryName = $file.Replace($parentPath, "")
                Write-Host "Adding $entryName..."                 Write-Host "Adding $entryName..."
                [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile(                 [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile(
Line 151: Line 159:
        $session.Open($sessionOptions)         $session.Open($sessionOptions)
-        $filePath = [WinSCP.RemotePath]::EscapeFileMask($archivePath+        $session.PutFileToDirectory($archivePath, $remotePath) | Out-Null
-        $session.PutFiles($filePath, $remotePath).Check()+
        Write-Host "Archive $archiveName uploaded."         Write-Host "Archive $archiveName uploaded."
-        & "$env:WINSCP_PATH\WinSCP.exe" "$sessionUrl" /refresh "$remotePath"+        # Refresh the remote directory in WinSCP GUI, if -refresh switch was used 
 +        if ($refresh) 
 +        { 
 +            Write-Host "Reloading remote directory..." 
 +············& "$env:WINSCP_PATH\WinSCP.exe" "$sessionUrl" /refresh "$remotePath" 
 +        }
    }     }
    finally     finally
Line 195: Line 207:
Use the //7-zip path// to select an alternative path to the ''7z.exe'' or ''7za.exe'', particularly if you are using a portable version. The option is available on the [[ui_pref_commands|Preferences dialog]] only. Use the //7-zip path// to select an alternative path to the ''7z.exe'' or ''7za.exe'', particularly if you are using a portable version. The option is available on the [[ui_pref_commands|Preferences dialog]] only.
-In the //Session log file// you can specify a path to a [[logging|session log file]] (for uploading). The option is available on the [[ui_pref_commands|Preferences dialog]] only.+In the //Session log file//, you can specify a path to a [[logging|session log file]] (for uploading). The option is available on the [[ui_pref_commands|Preferences dialog]] only.
 +In the //Keyboard shortcut//, you can specify a [[custom_key_shortcuts|keyboard shortcut]] for the extension. The option is available on the [[ui_pref_commands|Preferences dialog]] only.

Last modified: by martin