WinSCP "Too many parameters for command 'open'." error - batch-file

I am trying to connect to an SFTP with the following command to move all .csv files from one location to another and I'm getting the "Too many parameters for command 'open'." error.
option echo off
option batch on
option confirm off
open sftp://XXX#XXX.com/ —hostkey="ssh-rsa 2048 XX:XX:XX:XX:XX:XX:XX" —rawsettings ProxyMethod=3 ProxyHost=proxy.uk.XXX.com
cd /XX/XX/XX/IN/LOAD
lcd \\XX.local\EMEA\XX\XX\Import_Location
put *.csv -nopreservetime=on -nopermissions=on
exit
I added the —hostkey parameter due to the "The server's host key was not found in the cache" error, the batch file was working fine before that, but I want to correct the host key error.
I checked all the dashes, the quotes, the only thing I'm confused about is whether the hostkey parameter is correct. The information online on WinSCP and some forums says you have to use SHA-256 fingerprint of the host key only which is a different format to the MD5 detail XX:XX:XX:XX.... Please can you help which one it is?
—hostkey="ssh-rsa 2048 XX:XX:XX:XX:XX:XX:XX"
OR
—hostkey="ssh-rsa 2056 AbC50IDzyx.....="
This is a similar query to mine, but I cannot see what the difference is so that theirs works and mine doesn't. Thank you.

The symbol you have at the beginning of —hostkey and —rawsettings is not a simple hyphen-minus (-), but em-dash (—).
Please use hyphen-minus (-) – what is the dash that you find on the standard English [and other] keyboards.
Or even easier, have WinSCP GUI generate a script template for you.
So actually you have the very same problem as in WinSCP forum post you referred to.
Other questions with the same error message, but different problem:
WinSCP command line - Too many parameters for command 'open' when using -rawtransfersettings switch
Getting "Too many parameters for command", when calling WinSCP command-line from VBA
FTP "Too many parameters for command 'synchronize'" with WinSCP

Obtaining the correct hostkey fingerprint:
https://winscp.net/eng/docs/faq_hostkey

Related

using output from first line of code for input to 2nd line of code

I am getting a "File not found" error with trying to run Outlook in batch. Most likely due to an error in the way I am formatting the code. The script takes the contents of clipboard provided by 'getclip' as %1, zips it to clips.zip, uses && to pass to ipmnote which attaches it to a pre-loaded Outlook email
My original layout (which works) uses more lines of code and includes a mid-step of creating a file to be compressed. In trying to simplify the routine, I am getting errors saying Outlook cannot be found.
Outlook.exe is already in my System Path and I normally call it in using only the exe name. But I get the same "can't be located" error even when adding full path the file as shown here.
getclip>7z.exe a Clips.zip %1 -y && "C:\Program Files (x86)\Microsoft
Office\root\Office16\OUTLOOK.exe" /c ipm.note /m "email&subject=CLips.zip"
/a Clips.zip
Thanks for the quick reply. But the problem was the attachment. The error shown is somewhat open to interpretation since it implies that the issue is that Outlook cannot be found. In fact, what it could not find was the "clips.zip" file needed to attach it. Once i added the path to find the attachment, it works perfectly.
Sometimes, it helps to write in and ask the question. By following testing the sequence for each step of the outlook command, i found the issue was only there when i added the attachment with the /a at the end. By giving the full path to find 'clips.zip', all errors are gone and the email is perfect.
The broken line in the code was created by posting the code using the "Code" button. I added characters as needed to force it to display properly
I am sure there is a better way and I started to mention this but i figured most people would know that the proper path to Outlook especially being in quotes and all would not have a carriage return in the middle"

"Invalid SHA1 hash format" error calling signtool from msbuild or command line

I am trying to sign my assemblies and setup files during project build using SignTool.exe. Following this answer I wanted to use the /sha1 option so that I don't need to specify the certificate password. However, when I do this I am getting an "Invalid SHA1 hash format" error. I have tried both from an MSBuild Exec task, from a Visual Studio Developer Command prompt and from a batch file all with the same error.
The command I'm trying is (obviously with a different key):
signtool.exe sign /a /sha1 ‎1234567890abcdef1234567890abcdef12345678 /tr http://timestamp.comodoca.com /td SHA256 /v Setup.msi
I think my certificate is installed correctly and the SHA1 key is correct as it works with the SignFile MSBuild task correctly. I'd just use that but I also need to be able to sign my installer files which aren't built with MSBuild and hence need to be signed from a batch script.
So what could be the problem and how do I fix it?
I had the same problem and found out that there might be a hidden UNICODE character which causing this error. Just copy the text to a new Notepad instance and back and it will work.
Alternatively, place the cursor in this location:
/sha1 <cursor>abcdefg
Then press BACKSPACE. If you have to press BACKSPACE twice to get the cursor next to the "/sha1" directive, there was an invisible character. Then just type space and you are done.
Stupid mistake and I can't believe it took so long to realise. I had an extra space character before the thumbprint string which was the cause of the error.
Even after fixing that though I then got another error:
No certificates were found that met all the given criteria.
Running the command again with the /debug option listed all of the certificates it attempted to use and
After Hash filter, 0 certs were left.
The hash SHA1 hash for the certificate I wanted to use was exactly the same as I specified with the only exception being that the hash was all in upper-case letters. So tried the command again with the hash in all upper-case letters and... it worked.
As I haven't seen this requirement documented anywhere I thought I'd provide the answer here.
I solved it by providing the thumprint in the build command itself as follows:
msbuild /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:PackageCertificateThumbprint=897C9032E6BD06D32A315173D09C93B06CBDE1B4
remove the thumbprint from .csproj it should look like this.
<PackageCertificateThumbprint></PackageCertificateThumbprint>

Using bukhantsov.org command line query output with options

I am trying to use the tool here business objects query builder output
And there are virtually no examples, so I'm struggling to make it work. It produces no errors, but outputs no file in the directory where the batch file is, that I can see.
Here is the code inside querybuilder.bat:
set lib=c:\Program Files\Business Objects\Common\4.0\java\lib
java -cp "querybuilder.jar;poi-3.8-20120326.jar;%lib%\*" org.bukhantsov.querybuilder.Program %*
Here is the code inside what I am running, which I've named RunQuery_ALLACTIVE.bat, except of course with my Server, Username, and Password changed for the purpose of this post.
I have this all on one line, with no line breaks.
querybuilder.bat -cms:SERVER -username:OURUSERNAME -password:OURPASSWORD -query:"SELECT * FROM CI_INFOOBJECTS where SI_SCHEDULE_STATUS = 9 order by SI_NAME" -auth:windowsad -excel "Output.xls"
Can't tell if the - options go on different LINES ?
Can't tell if I'm supposed to put output file in quotes, or if it should be an existing file or not?
can't tell if for Windows AD (which we use), I would put "Windows AD" or WindowsAD, I'm assuming no spaces obviously.
Tons of unanswered questions on this tool - it LOOKS cool, but has anyone actually successfully used it? Can't really find comments or history on the 'net..
To answer your questions:
The options go on the same line, not on different ones
As Joe said, you'll need to specify the output file as -excel:"Output.xls"
If you want to use Windows AD, you'll probably need to specify secWinAD (case-sensitive).
If you're not sure about the command line options, I suggest you build up gradually: first only specify the required options, then add the optional ones one by one so you know which one is giving you problems.
Also, I noticed that the download page contains a version compiled for XI3.x and BI4. Make sure you use the correct version, corresponding to the version of BusinessObjects you're using. Also, verify the path in the batch file to see if it points to a valid folder containing the JAR files for the BusinessObjects environment.
Update:
I just noticed that the same author/developer created another application (GUI, not command line) that might be a bit easier to use. Have a look here.

Find multiple files from the command line

Description:
I am searching a very large server for files that is on a different server. right now I open command prompt and type
DIR [FILE NAME] /S/4
This returns the server location of the file with some other stuff that is not really needed.
Question:
I have a lot of files to search and one by one input into the above command could take forever. Is there a way I could input all of the names of all the files and only search once and the search results would only need to show file name and location?
First, I hope you don't mean DOS, but rather Windows cmd or batch.
You can certainly write a script that will run your DIR command once per file being sought.
But what you most likely want instead is to search once and print the path of each file found. For this you can use PowerShell's FindChildItem or the improved one posted here: http://windows-powershell-scripts.blogspot.in/2009/08/unix-linux-find-equivalent-in.html
It will be something like:
Find-ChildItem -Name "firstfile.txt|secondfile.txt|..."
Another approach is to install msys or cygwin or another Linux tools environment for Windows and use the Linux find command.

How do I view or rename a file with missing extension?

I have a strange file in my file system without the extension part. The filename is "15.". The weird thing is that it is not one of those without the dot part (like just "15"), but the one with the dot but no extension ("15.") -- it is literally an illegal filename in windows, and not sure how did it get created in the first place.
I know it is a text file and it is about 15KB in size; however, due to the weirdness in name, I can't open it with any application -- I've tried to open in notepad, wordpad, etc., have tried the 'type' command to spit it out on commans shell, tried to shell-open enclosing filename in quotes, and so on -- all methods result in a 'file not found' error except the notepad, which says '15.txt' is not found.
Due to the nature of the issue and the way search engines optimize the search, it is extemely hard to search for an answer in any of the search engines online. So, I just wanted to put this question out there and see if anybody had to deal with a similar issue and have found any way to rename the file or even to change the extension.
Filenames that are valid in NTFS but cannot be used from Windows can be created when accesing disks or shares from other operating systems like Linux.
If you don't have a Linux installation at hand, then get hold of a "live" CD, boot Linux, and change the filename.
That may sound like a hassle, but Windows-only solutions (moving stuff around, deleting the directory) are even worse.
Use REN: http://ss64.com/nt/ren.html
It is a command prompt command (run > cmd > cd wherever > ren 15. 15.txt )

Resources