Site list does not update / window size always resets / open same session

Advertisement

jameslx
Guest

Site list does not update / window size always resets / open same session

Hello,

STORY - I programmed myself a quick Windows batch based script which creates new/modifies existing WinSCP sessions in registry (or with /ini options - really does not make any difference).

BUG #1 - The problem is that when a new session is started to an open WinSCP instance I always get "Host XXXX does not exist" (new instances work). The problem is that the application does not update it's sessions list automatically. I can trigger it myself by going to "Session>Sites>Site Manager", but I shouldn't really need to do that - the program should do it.

BUG #2 - I do not have a logical explanation for this. When I do > C:\Progra~2\WinSCP\WinSCP.exe "SESSION NAME" > the WinSCP window always resets to a very uncomfortable size (600x600 maybe, it's hard to tell on a 18" screen)

Waiting for any possible resolutions.

Regards.

Reply with quote

Advertisement

jameslx
Guest

Forgot to add - Is it possible to somehow check if the session is already open pragmatically (or in some other way) and just not open a new tab if the session is already open?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

Re: Site list does not update / window size always resets / open same session

jameslx wrote:

when a new session is started to an open WinSCP instance
What does this mean?

BUG #2 - I do not have a logical explanation for this. When I do > C:\Progra~2\WinSCP\WinSCP.exe "SESSION NAME" > the WinSCP window always resets to a very uncomfortable size (600x600 maybe, it's hard to tell on a 18" screen)
Which window? Login dialog? The main window of an existing WinSCP instance?

Reply with quote

jameslx
Guest

Sorry for the late reply, I forgot about the thread...

when a new session is started to an open WinSCP instance

I meant when WinSCP is already open (a process is running / WinSCP.exe is visible in Task Manager).
When the application is not active/not open - it works, no errors occur, session is created.

Which window? Login dialog? The main window of an existing WinSCP instance?

The whole window is resized. The login window is the same size as always.
If it makes a difference - I create a password entry in the registry, so no password prompt occurs while connecting (if the password correct of course).

I use v5.7.5 (currently the latest one).

Reply with quote

Advertisement

jameslx
Guest

martin wrote:

When does it resize? Before an authentication or after?

It resizes before the authentication window (yes, there is no login window, no inputs occur during the connection process).

However, at the moment, the problem somehow disappeared, I did not upgrade the application, did not even turn it off, it somehow fixed itself (at best, I opened and closed some sessions). Do not really know why this happened, but the problem with "host does not exist" is still there.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

jameslx wrote:

but the problem with "host does not exist" is still there.
What are the exact steps to reproduce this?
Do you create a new site in a separate instance, close it, and then you open the new site in the existing instance from a command-line/desktop shortcut?

Reply with quote

jameslx
Guest

I have set a custom uri handler "caesar://" and i use it as a shortcut to open heidisql, winscp, putty and setup quick tunnels from a web page (a control panel). However, the same error can be produced (at least on my computer) just by accessing a .bat file

@echo off
mode con: cols=100 lines=10
setlocal enableextensions disabledelayedexpansion
echo "CAESAR URI handler has started..."

:: winscp         - caesar://sftp:88.88.88.88:22:root:null:null:null:null/yourpassword/null/null/#etc#lighttpd#/

:: parse the uri parameters
for /f "tokens=1 delims=:" %%C in ("%line%") do set "type=%%C"
for /f "tokens=2 delims=:" %%C in ("%line%") do set "sship=%%C"
for /f "tokens=3 delims=:" %%C in ("%line%") do set "sshport=%%C"
for /f "tokens=4 delims=:" %%C in ("%line%") do set "sshuser=%%C"
for /f "tokens=2 delims=/" %%C in ("%line%") do set "sshpass=%%C"
for /f "tokens=3 delims=/" %%C in ("%line%") do set "sqluser=%%C"
for /f "tokens=4 delims=/" %%C in ("%line%") do set "sqlpass=%%C"
for /f "tokens=5 delims=/" %%C in ("%line%") do set "sftpdir=%%C"
for /f "tokens=5 delims=:" %%C in ("%line%") do set "remoteip=%%C"
for /f "tokens=6 delims=:" %%C in ("%line%") do set "remoteport=%%C"
for /f "tokens=7 delims=:" %%C in ("%line%") do set "localport=%%C"

:: sftp directory
set sftpdir=%sftpdir:#=/%
if "%sftpdir%"=="" set sftpdir="/%sshuser%"
if "%sftpdir%"=="null" set sftpdir="/%sshuser%"
:: let's just user's home directory (winscp does not reload it's sites database if the application is active and registry changes)
set sftpdir="/%sshuser%"

:: create a popup message file
@echo Set objArgs = WScript.Arguments > %AppData%\\caesarurimsg.vbs
@echo messageText = objArgs(0) >> %AppData%\\caesarurimsg.vbs
@echo MsgBox messageText,0,"Caesar URI Notification" >> %AppData%\\caesarurimsg.vbs

:: check if winscp is installed
if exist "C:\Progra~1\WinSCP\WinSCP.exe" set apploc_winscp=C:\Progra~1\WinSCP\WinSCP.exe
if exist "C:\Progra~2\WinSCP\WinSCP.exe" set apploc_winscp=C:\Progra~2\WinSCP\WinSCP.exe
if "%apploc_winscp%"=="" (
   cmd /c cscript %AppData%\\caesarurimsg.vbs "Could not find WinSCP.exe in the default location. If it it not installed, - install it, if it is - check the script location inside %SystemRoot%\caesaruri.bat."
   exit
)

:: add registry values for winscp (if they do not already exist)
:: reference here: https://winscp.net/eng/docs/custom_distribution#distributing_passwords
if "%type%"=="sftp" set create_sftp_reg=1
set "winscpkey=HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\Sessions\%sessionname%"
if defined create_sftp_reg (
   echo "Preparing WinSCP..."
   REG QUERY "%winscpkey%">nul && (
      echo "- Session has already been created before..."
   ) || (
      echo "- Creating a new session..."
      REG ADD "%winscpkey%" /f /v "HostName" /t REG_SZ /d "%sship%" > NUL
      REG ADD "%winscpkey%" /f /v "Username" /t REG_SZ /d "%sshuser%" > NUL
      REG ADD "%winscpkey%" /f /v "PortNumber" /t REG_DWORD /d "%sshport%" > NUL
      REG ADD "%winscpkey%" /f /v "PasswordPlain" /t REG_SZ /d "%sshpass%" > NUL
   )
)

:: open a winscp connection (to solve a "Host not found" (tested up to v5.8) bug when creating new sessions - when a new session is created and error occurs, go to "Session>Sites>Site Manager" (a new dialog will open), close the dialog - problem will not occur for the same session next time)
if "%type%"=="sftp" (
   echo "- Opening WinSCP..."
   if not "%sftpdir%"=="" (
      REG ADD "%winscpkey%" /f /v "RemoteDirectory" /t REG_SZ /d "%sftpdir%" > NUL
   )
   %apploc_winscp% "%sessionname%"
)

:: just in case
exit

The script above can be called using the code below via cmd.exe

hstart.exe /UAC "caesaruri.bat %1"

However, I use the custom uri handler to call it, it can be set up with .reg (contents below)

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CAESAR]
@="url:caesar protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\CAESAR\shell]

[HKEY_CLASSES_ROOT\CAESAR\shell\open]

[HKEY_CLASSES_ROOT\CAESAR\shell\open\command]
@="hstart.exe /UAC \"caesaruri.bat %1\""

NOTE: I minimized the .bat script to only show winscp, I did a fast review, but there might be some bugs/missing code, but I think that the most important parts can be understood without even executing the code.

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum