WinSCP - Unknown command and '.log' is not recognized as an internal or external command - powershell

Context: I'm using powershell to instantiate a batch file to execute the synchronize remote command in WinSCP and pull in fresh data from a remote directory to my local directory. See screenshots below for contents of the WinSCP commands and the batch file contents.
When I try to execute I am able to successfully authenticate but I see 2 errors.
Batch file contents:
winscp.com /script=winscp_commands_ar_history.txt
/log=C:/Users/REDACTED/Desktop/AR_History_Report/winscp_log_ar_history.txt
WinSCP commands:
option batch abort
option confirm off
open sftp://REDACTED:REDACTED#sftp.REDACTED.com
-hostkey="ssh-rsa 2048 cc:ea:2e:03:96:ca:e7:c0:59:74:13:a8:XX:XX:XX:XX"
synchronize remote /export/GroupAccess/REDACTED/Cognos Reporting/CogTest
C:/Users/REDACTED/Desktop/AR_History_Report
exit
Powershell output:
Errors:
Unknown command '-hostkey=ssh-rsa 2048 cc:ea:2e:03:96:ca:e7:c0:59:74:13:a8:XX:XX:XX:XX'.
'/log' is not recognized as an internal or external command,
operable program or batch file.
Question: How do I resolve these 2 errors? I suspect the last one is related to environment variables since it seems powershell didn't recognize the WinSCP log command so I've added WinSCP to my PATH environment variable but I'm still getting the same errors. Can someone please assist? Thank you.

Both your batch file and WinSCP script have line breaks in the middle of commands. Moreover, in the synchronize command you need to wrap the path with spaces to double quotes.
The batch file should be:
winscp.com /script=winscp_commands_ar_history.txt /log=C:/Users/REDACTED/Desktop/AR_History_Report/winscp_log_ar_history.txt
And the script file should be:
option batch abort
option confirm off
open sftp://REDACTED:REDACTED#sftp.REDACTED.com -hostkey="ssh-rsa 2048 cc:ea:2e:03:96:ca:e7:c0:59:74:13:a8:XX:XX:XX:XX"
synchronize remote "/export/GroupAccess/REDACTED/Cognos Reporting/CogTest" C:/Users/REDACTED/Desktop/AR_History_Report
exit
As an aside, as #mklement0 commented, you don't need another powershell process to invoke a batch file from PowerShell - just invoke batch files directly: .\ar_trigger_history.bat

Related

i have a .ps1 file which fetch folder content from the folder.how to run that .ps1 file from jmeter so i can do performance testing?

I have a .ps1 file which fetch folder content from the folder. How to run that .ps1 file from jmeter so I can do performance testing?
PS C:\Users\######> D:\KANHA_####\niii1.ps1
Add OS Process Sampler to your Test Plan
Configure it as follows:
Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Argument 1: -File
Argument 2: C:\Users######> D:\KANHA_####\niii1.ps1
That's it, when you run the test JMeter will execute the script and you will be able to see the output using i.e. View Results Tree listener.
More information: How to Run External Commands and Programs Locally and Remotely from JMeter article for more information.
P.S. You might need to amend execution policy settings

Open a site directly in FileZilla using the command line

I'm trying to open a site I created in FileZilla using the command line. This is what have in my .bat file:
#echo off
filezilla.exe -c "0/mysitename"
pause
I'm getting the following error. How can I fix it?
'filezilla' is not recognized as an internal or external command,
operable program or batch file.
In order for an executable to be executed by name, the filezilla.exe file needs to be included on the path. This can be accomplished by
set path=%path%;the\directory\where\filezilla\resides
OR, you can use
the\directory\where\filezilla\resides\filezilla.exe -c "0/mysitename"

cmd file that starts plink.exe from a nant script not working

I have a .cmd file that start plink.exe and runs several commands.
This works great if I open a command prompt and run the .cmd file.
It does not work when I call the .cmd file from an nant script.
Oh. the nant script is on a windows machine and the plink.exe is connecting to a linux machine.
Any ideas?
Is the NANT script running under the same user, when you manually run it? Make sure the user's have enough access rights.
Do you notice any error messages? Perhaps it is not founding the command executable i.e. plink.exe in the PATH environment variable.
You can put following in your .cmd file:
echo %PATH%
Compare what you get when you run directly on the prompt and run through nant script. Please also provide the plink command line you are using in the .cmd file.

TeamCity running Powershell script, but failing to execute a batch file

I am currently in the process of implementing a deployment method using Teamcity, which runs a Powershell script on my Build Agent, which then configures my Production environment etc.
I have a problem with the Powershell script though, in that it can't seem to run the batch file from it.
The script runs perfectly if I run it manually, it only fails when run via TeamCity.
In the build log I am getting the error:
'myBatchFile.bat' is not recognized as an internal or external command, operable program or batch file.
The batch file and the powershell script are in the same directory and the batch file is called as such:
cmd /c Deploy.bat
I have my TeamCity configuration set up to have the build step for this as:
Script: File
ScriptExecutionMode: Execute script with -File argument
Script Arguments: None
Additional CMD line params: None
I had originally not used the cmd to try to execute the batch file, but executing the batch file like .\Deploy.bat did not seem to work either.
Is there an additional thing I need to set up in order to get the batch file to run? The rest of the script runs fine, just the call to the batch that doesn't.
This is a bit of a wild stab as it's difficult to predict what's happening, but from the description it seems like the path is been altered in the script and it's also dynamic as TeamCity creates temp directories, but if you replace:
cmd /c Deploy.bat
with
cmd /c "$(Split-Path $myinvocation.MyCommand.Path)\Deploy.bat"
then I think this will be able to located the deploy script.
Let me know how it goes.

Run a exe file through a power shell script

I want to run a power shell script which can run a exe file and following are my requirements.
I have that exe file in a remote server location(//ES-WEBSRV01/DBMigration) which is shared to my local machine. Also I want to run that ps file through a cmd.exe.
You can simply call it like any other program:
\\ES-WEBSRV01\DBMigration\something.exe
or, if it contains spaces somewhere along the path:
& "\\ES-WEBSRV01\DBMigration\some thing.exe"
I have no clue what you mean by »Also I want to run that ps file through a cmd.exe.«, though. If you mean that you need a batch file and want to run the PowerShell script from there, then:
powershell -file myscript.ps1