Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

penguinjeff

updated wrapper.vbs

' c:\helpers\wrapper.vbs

' Written by Jeff Sadowski to use with Notepad++
' expects argument of form <browser>;<file_location>

' expected to be used from %APPDATA%\Notepad++\shortcuts.xml following is an documented entry followed by an example entry
' <Command name="Launch in <Browser Name>" <Key Sequence>>wscript &quot;<Path to this file>&quot; &quot;<commandline browser exe name>;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="66">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;firefox;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;iexplore;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;chrome;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="88">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;safari;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in Opera" Ctrl="yes" Alt="yes" Shift="yes" Key="79">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;opera;$(FULL_CURRENT_PATH)&quot;</Command>

' expects in winscp under Options under Preferences under Storage "Append session name to temporary path"
' and use session names with username@servername syntax (the default names)

'last updated 2014 08 27

'Regular Expression
dim RE
Set RE = New RegExp
RE.IgnoreCase = True

'WScript Shell
dim wsh
Set wsh = CreateObject( "WScript.Shell" )

'directory where winscp writes temporary files
'default temporary directory for winscp with session append on.
dim scpdir
scpdir=Replace(wsh.ExpandEnvironmentStrings( "%TEMP%" ),"\","\\") & "\\scp[0-9]*\\([^\\]*)\\"

'temporary variable to get the browser and file_location from
dim data
'get directory and browser
data=Split(WScript.Arguments(0),";")
'url to send to the web browser
'for now set the url to the input directory
dim url
url=data(1)

'session name
dim session
'usename from session
dim user
'servername from session
dim server

'if the file name ends in php replace %TEMP%/scp<number>/<session name>/<path from root of web server> with <web server address> and replace all \ with /
url=replace_directory("php" ,scpdir & "var\\www\\html"       ,"http://<server>"                ,url)
url=replace_directory("html",scpdir & "var\\www\\html"       ,"http://<server>"                ,url)
url=replace_directory("cgi" ,scpdir & "var\\www\\cgi-bin"    ,"http://<server>/cgi-bin"        ,url)
url=replace_directory("php" ,scpdir & "home\\.*\\public_html","http://<server>/~<user>"        ,url)
url=replace_directory("html",scpdir & "home\\.*\\public_html","http://<server>/~<user>"        ,url)
url=replace_directory("cgi" ,scpdir & "home\\.*\\cgi-bin"    ,"http://<server>/~<user>/cgi-bin",url)

'run the browser with the replaced url according to the rules above
CreateObject("Wscript.Shell").Run data(0)+" """+url+""""
'if the file name ends in <extension> replace <directory> with <url> and replace all \ with / otherwise return data unmodified
Function replace_directory(extension,directory,myurl,data)
 RE.Pattern = directory & ".*" & extension & "$"
 If RE.Test(data) Then
  session=RE.Replace(data,"$1")
  ' session names are stored here in the registry for winscp.
  user=wsh.RegRead( "HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\Sessions\" & session & "\UserName" )
  server=wsh.RegRead( "HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\Sessions\" & session & "\HostName" )
  RE.Pattern = "<server>"
  If RE.Test(myurl) Then
   myurl=RE.Replace(myurl,server)
  End If
  RE.Pattern = "<user>"
  If RE.Test(myurl) Then
   myurl=RE.Replace(myurl,user)
  End If
  RE.Pattern = directory
  replace_directory=Replace(Replace(RE.Replace(data,myurl),"\\","\"),"\","/")
 Else
  replace_directory=data
 End If
End Function
martin

Re: Advanced Temporary File Question

penguinjeff wrote:

under Options under Preferences under Storage I selected "Append session name to temporary path" and the default names are usually username@servername

Reference to documentation:
https://winscp.net/eng/docs/ui_pref_storage
penguinjeff

Advanced Temporary File Question

When editing files on the remote server I see that winscp edits the file in a mostly easy to follow directory of where the file is located on the server. Is there a way to change the temporary path to be more informed about what server this is on? It looks like they are using session id as the directory under temp
IE:
%TEMP%\scp<session id>\<path on server>\

I would like something like
%TEMP%\scp\<remote server>\<username>\<session id>\<path on server>\

notice I moved the session id further down the path

So that I can more easily setup some scripts in notepad++ to open pages up on the correct servers.
Or maybe there is an easy way to get the servername and username from the session id in a script?

-----------------------------------------------------------------------------------------

Update:

Found an option that gives me what I want.

under Options under Preferences under Storage I selected "Append session name to temporary path" and the default names are usually username@servername

which works perfect.

------------------------------------------------------------------------------------------
My script I use it in with documentation on how I use it

' c:\helpers\wrapper.vbs

' Written by Jeff Sadowski to use with Notepad++
' expects argument of form <browser>;<file_location>

' expected to be used from %APPDATA%\Notepad++\shortcuts.xml following is an documented entry followed by an example entry
' <Command name="Launch in <Browser Name> <Key Sequence>>wscript &quot;<Path to this file>&quot; &quot;<commandline browser exe name>;$(FULL_CURRENT_PATH)&quot;</Command>"
' <Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="66">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;firefox;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;iexplore;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;chrome;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="88">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;safari;$(FULL_CURRENT_PATH)&quot;</Command>
' <Command name="Launch in Opera" Ctrl="yes" Alt="yes" Shift="yes" Key="79">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;opera;$(FULL_CURRENT_PATH)&quot;</Command>

' expects in winscp under Options under Preferences under Storage "Append session name to temporary path"
' and use session names with username@servername syntax (the default names)

'last updated 2014 07 29


'temporary variable to get the browser and file_location from
dim data
'url to send to the web browser
dim url
'directory where winscp writes temporary files
dim tempdir
'Regular Expression
dim RE
'WScript Shell
dim wsh

Set RE = New RegExp
RE.IgnoreCase = True

Set wsh = CreateObject( "WScript.Shell" )
'default temporary directory for winscp with session append on.
tempdir=Replace(wsh.ExpandEnvironmentStrings( "%TEMP%" ),"\","\\") & "\\scp[0-9]*\\.*@.*\\"

'get directory and browser
data=Split(WScript.Arguments(0),";")
'for now set the url to the input directory
url=data(1)

'if the file name ends in php replace %TEMP%/scp<number>/<user>@<server>/<path to root of web server> with <web server address> and replace all \ with /
url=replace_directory("php" ,tempdir & "var\\www\\html"       ,"http://<server>"                ,url)
url=replace_directory("html",tempdir & "var\\www\\html"       ,"http://<server>"                ,url)
url=replace_directory("cgi" ,tempdir & "var\\www\\cgi-bin"    ,"http://<server>/cgi-bin"        ,url)
url=replace_directory("php" ,tempdir & "home\\.*\\public_html","http://<server>/~<user>"        ,url)
url=replace_directory("html",tempdir & "home\\.*\\public_html","http://<server>/~<user>"        ,url)
url=replace_directory("cgi" ,tempdir & "home\\.*\\cgi-bin"    ,"http://<server>/~<user>/cgi-bin",url)

'run the browser with the replaced url according to the rules above
CreateObject("Wscript.Shell").Run data(0)+" """+url+""""
'if the file name ends in <extension> replace <directory> with <url> and replace all \ with / otherwise return data unmodified
Function replace_directory(extension,directory,url,data)
 RE.Pattern = directory & ".*" & extension & "$"
 If RE.Test(data) Then
  RE.Pattern="\<server\>"
  If RE.Test(url) Then
   RE.Pattern=".*\\([^@]*)@([^\\]*).*"
   servername=RE.Replace(data,"$2")
   RE.Pattern="\<server\>"
   url=RE.Replace(url,servername)
  End If
  RE.Pattern="\<user\>"
  If RE.Test(url) Then
   RE.Pattern=".*\\([^@]*)@([^\\]*).*"
   username=RE.Replace(data,"$1")
   RE.Pattern="\<user\>"
   url=RE.Replace(url,username)
  End If 
  RE.Pattern = directory
  replace_directory=Replace(Replace(RE.Replace(data,url),"\\","\"),"\","/")
 Else
  replace_directory=data
 End If
End Function