Topic "Command-line Options - WinSCP version in human and raw ways"

Author Message
Makc666
[View user's profile]

Joined: 2016-12-08
Posts: 52
Location: MSK-RU
Martin,

I wasn't able to find this on anywhere in docs.

The only way I was able to find to get WinSCP version is to run:
Code:
winscp.com /help

This will output on the first line WinSCP version.
Code:
WinSCP, Version 5.9.3 (Build 7136)
Copyright (c) 2000-2016 Martin Prikryl

Usage:
WinSCP [/script=file] [/command cmd1...] [/parameter // param1...]
...
...


I have just met with the requirement to check WinSCP version in scripting.
For example if someone is trying to run old version which doesn't support some command or trying to run incompatibility version then, for example, stop him.

The best way to do this one is to have in Command-line Options a parameter like:
/rawversion (may be also /version).

Also we can have this one in Scripting and Task Automation - Commands.

rawversion has to display it in raw way like: 50903 or may be 7136 (assuming that build version is always increasing).
and
version has to display it in human way like: WinSCP, Version 5.9.3 (Build 7136)

The best close example for such command is in PHP.

They use PHP_VERSION_ID and I can check very easily:
Code:
if (PHP_VERSION_ID < 50100) {
   //do one thing
}else{
   //do another thing
}

or
Code:
if (PHP_VERSION_ID < 50207) {
    define('PHP_MAJOR_VERSION',   $version[0]);
    define('PHP_MINOR_VERSION',   $version[1]);
    define('PHP_RELEASE_VERSION', $version[2]);

    // and so on, ...
}


Code:
// PHP_VERSION_ID is defined as a number, where the higher the number
// is, the newer a PHP version is used. It's defined as used in the above
// expression:
//

$version_id = $major_version * 10000 + $minor_version * 100 + $release_version;


For example I have PHP 5.6.19
print PHP_VERSION_ID; will give me 50619

Thank you!
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26572
Location: Prague, Czechia
Code:
powershell -Command [System.Diagnostics.FileVersionInfo]::GetVersionInfo('winscp.exe').FileVersion
5.9.3.7136


See https://stackoverflow.com/q/30686/850848
Makc666
[View user's profile]

Joined: 2016-12-08
Posts: 52
Location: MSK-RU
martin wrote:
Code:
powershell -Command [System.Diagnostics.FileVersionInfo]::GetVersionInfo('winscp.exe').FileVersion
5.9.3.7136


See https://stackoverflow.com/q/30686/850848


I do understand this one, but in such way you have to use external utility. Also no guaranty you will have powershell.

So having such native switch will be wonderful!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26572
Location: Prague, Czechia
Makc666 wrote:
I do understand this one, but in such way you have to use external utility. Also no guaranty you will have powershell.

99% of WinSCP users have PowerShell.

Anyway, if you want a pure batch file solution, use:

Code:
@echo off
echo WScript.Echo CreateObject("Scripting.FileSystemObject").GetFileVersion(WScript.Arguments(0)) > version.vbs
cscript /nologo version.vbs winscp.exe
del version.vbs


See https://stackoverflow.com/q/602802/850848#604411
Makc666
[View user's profile]

Joined: 2016-12-08
Posts: 52
Location: MSK-RU
Martin, I understand this one.

But again (sorry) the best way is to get native output from WinSCP rather then creating any temp files or scripts.

Also you can try to get the version this way:

Code:
@ECHO OFF
if defined ProgramFiles(x86) (
   set "winscp_com=%ProgramFiles(x86)%\WinSCP\WinSCP.com"
) else (
   set "winscp_com=%ProgramFiles%\WinSCP\WinSCP.com"
)
setlocal EnableDelayedExpansion
for /f "tokens=2,3,4,* delims= " %%a in ('"%winscp_com%" /help ^| findstr /B /I /R WinSCP ^| findstr /I /R Build') do (
   echo %%b %%c %%d
)
PAUSE


But again it is not the best variant as it is very sensitive.

For example if you will replace
Code:
for /f "tokens=2,3,4,* delims= " %%a in ('"%winscp_com%" /help ^| findstr /B /I /R WinSCP ^| findstr /I /R Version') do (

with
Code:
for /f "tokens=2,3,4,* delims= " %%a in ('"%winscp_com%" /help ^| findstr /B /I /R "WinSCP, Version"') do (

it will not work.
Looks like some glitch with double quotes in "%winscp_com%" and "WinSCP, Version" together.

So, once again, best way is native output.

If you can implement this one it will be wonderful.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26572
Location: Prague, Czechia
Sorry, but I do not think this is necessary.

WinSCP has its version stored in the native binary header, as any other Windows binary.

There are dozens standard tools and ways to retrieve that information.
Advertisements

You can post new topics in this forum






Search

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