Differences

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

extension_generate_http_url 2017-01-13 extension_generate_http_url 2020-09-22 (current)
Line 2: Line 2:
This extension allows you to generate HTTP URL of the selected file. This extension allows you to generate HTTP URL of the selected file.
-For the extension to work correctly, you may need to configure web root folder and possible other options.+For the extension to work correctly, you may need to configure web root folder and possibly other options. 
 + 
 +~~AD~~
This is an official [[extension|WinSCP extension]] and is distributed in WinSCP installer. This is an official [[extension|WinSCP extension]] and is distributed in WinSCP installer.
Line 8: Line 10:
<code powershell - GenerateHttpUrl.ps1> <code powershell - GenerateHttpUrl.ps1>
# @name        Generate &HTTP URL # @name        Generate &HTTP URL
-# @command      powershell.exe -ExecutionPolicy Bypass -STA -NoProfile -File "%EXTENSION_PATH%" -webRoot "%WebRoot%" -rootPath "%RootPath%" -hostName "%HostName%" -serverName "!@" -path "!/!" %Https% %Pause% %Clipboard% %Open%+# @command      powershell.exe -ExecutionPolicy Bypass -STA -NoProfile
 +#                  -File "%EXTENSION_PATH%" -webRoot "%WebRoot%" -rootPath "%RootPath%"
 +#                  -hostName "%HostName%" -serverName "!@" -path "!/" %Https% %Pause%
 +#                  %Clipboard% %Open% !&
# @description  Generates HTTP URL of the selected file # @description  Generates HTTP URL of the selected file
# @flag        RemoteFiles # @flag        RemoteFiles
-# @version      1+# @flag        ShowResultsInMsgBox 
 +# @version      5
# @homepage    ~~SELF~~ # @homepage    ~~SELF~~
-# @require      WinSCP 5.9.3+# @require      WinSCP 5.12
# @option      - -site group "URL" # @option      - -site group "URL"
# @option        - -site label "These options are site-specific." # @option        - -site label "These options are site-specific."
-# @option        WebRoot -site textbox "&Web root path"+# @option        WebRoot -site textbox "&Web root path:"
# @option        Https -site checkbox "Use HTTP&S" "" "-https" # @option        Https -site checkbox "Use HTTP&S" "" "-https"
-# @option        RootPath -site textbox "&URL root path (optional)" +# @option        RootPath -site textbox "&URL root path (optional):
-# @option        HostName -site textbox "&Web server hostname override (optional)"+# @option        HostName -site textbox "&Web server hostname override (optional):"
# @option      - group "Options" # @option      - group "Options"
-# @option        Pause checkbox "Display URL in console" "-pause" "-pause"+# @option        Pause checkbox "Display URL" "-pause" "-pause"
# @option        Clipboard checkbox "Copy URL to clipboard" "-clipboard" "-clipboard" # @option        Clipboard checkbox "Copy URL to clipboard" "-clipboard" "-clipboard"
# @option        Open checkbox "Open URL in web browser" "" "-open" # @option        Open checkbox "Open URL in web browser" "" "-open"
Line 34: Line 40:
    [Parameter(Mandatory = $True)]     [Parameter(Mandatory = $True)]
    $path,     $path,
-    [Switch]·+    [Switch]
    $https,     $https,
-    [Switch]·+    [Switch]
    $pause,     $pause,
-    [Switch]·+    [Switch]
    $clipboard,     $clipboard,
-    [Switch]· +    [Switch] 
-    $open+    $open
 +    [Parameter(Mandatory = $True, ValueFromRemainingArguments = $True, Position = 0)] 
 +    $paths
) )
Line 51: Line 59:
    }     }
-    if (($path.Length -lt $webRoot.length) -or +    $result = $Null 
- ·······($path.SubString(0, $webRoot.Length) -ne $webRoot))+ ···foreach ($filePath in $paths)
    {     {
-        throw "The path $path is not under web root $webRoot.+        $filePath = "$path$filePath
-    } + 
- ··· + ·······if (($filePath.Length -lt $webRoot.length) -or 
- ···if ($rootPath) + ···········($filePath.SubString(0, $webRoot.Length) -ne $webRoot))
- ···{ +
- ·······if ($rootPath.SubString($rootPath.Length - 1) -ne &quot;/")+
        {         {
-            $rootPath += "/"+            throw "**The path $filePath is not under web root $webRoot.**" 
 +        } 
 +         
 +        if ($rootPath) 
 +        { 
 +            if ($rootPath.SubString($rootPath.Length - 1) -ne "/") 
 +            { 
 +················$rootPath += "/" 
 +            } 
 +        } 
 +        else 
 +        { 
 +            $rootPath = "/"
        }         }
-    } 
-    else 
-    { 
-        $rootPath = "/" 
-    } 
-····$urlPath = $path.SubString($webRoot.Length) +········$urlPath = $filePath.SubString($webRoot.Length) 
-  +       $urlPath = ($urlPath -split "/" | %{ [System.Uri]::EscapeDataString($_) }) -join "/" 
- ···if ($https) +      
- ···{  +········if ($https) 
- ·······$protocol = "https://" + ·······{  
- ···+ ···········$protocol = "https://" 
- ···else + ·······
- ···+ ·······else 
- ·······$protocol = "http://"+ ·······
 + ···········$protocol = "http://" 
 +        } 
 + 
 +        if (!$hostName) 
 +        { 
 +            $hostName = $serverName 
 +        } 
 +         
 +        $url = "$protocol$hostName$rootPath$urlPath" 
 +        $result += $url 
 +        if ($paths.Count -gt 1) 
 +        { 
 +            $result += "`r`n" 
 +        } 
 + 
 +        if ($open) 
 +        { 
 +            Start-Process $url 
 +        }
    }     }
-    if (!$hostName)+    if ($pause)
    {     {
-        $hostName = $serverName+        Write-Host -NoNewline $result
    }     }
-     
-    $url = "$protocol$hostName$rootPath$urlPath" 
- 
-    Write-Host $url 
    if ($clipboard)     if ($clipboard)
    {     {
        Add-Type -Assembly PresentationCore         Add-Type -Assembly PresentationCore
-        [Windows.Clipboard]::SetText($url)  +        [Windows.Clipboard]::SetText($result)
-    } +
- +
-    if ($open) +
-    { +
-        Start-Process $url+
    }     }
    $result = 0     $result = 0
} }
-catch [Exception]+catch
{ {
-    Write-Host $_.Exception.Message+    Write-Host "Error: $($_.Exception.Message)"
    $result = 1     $result = 1
-    $pause = $true 
-} 
- 
-if ($pause) 
-{ 
-    Write-Host "Press any key to exit..." 
-    [System.Console]::ReadKey() | Out-Null 
} }
Line 118: Line 134:
</code> </code>
-===== Options =====+===== [[options]] Options =====
&screenshotpict(extension_generate_http_url) &screenshotpict(extension_generate_http_url)
Line 136: Line 152:
==== [[options]] Options ==== ==== [[options]] Options ====
-Uncheck the //Display %%URL%% in console// not to keep the console window, with the generated %%URL%%, open. +Uncheck the //Display %%URL%%// not to display a message box with the generated %%URL%%.
Uncheck the //Copy %%URL%% to clipboard// not to store the generated %%URL%% to the clipboard. Uncheck the //Copy %%URL%% to clipboard// not to store the generated %%URL%% to the clipboard.
 +
 +Check the //Open %%URL%% in web browser// to open the generated URL in your web browser.
 +
 +In the //Keyboard shortcut//, you can specify a [[custom_key_shortcuts|keyboard shortcut]] for the extension.
~~NOTOC~~ ~~NOTOC~~

Last modified: by martin