Topic "Advanced Temporary File Question"

Author Message
penguinjeff
[View user's profile]

Joined: 2014-07-28
Posts: 2
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

Code:

' 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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
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
_________________
Martin Prikryl
penguinjeff
[View user's profile]

Joined: 2014-07-28
Posts: 2
Code:

' 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
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License