Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

floschn

Re: Scripting in Powershell

thanks worked like a charm !

regards
floschn

Re: Scripting in Powershell

Thank You for your reply,

i will try it as soon as i am home.

THANKS!
martin

Re: Scripting in Powershell

The winscp.exe is a GUI application. PowerShell does not seem to wait for GUI application to exit before proceeding to the next comment. So the $LASTEXITCODE cannot contain the exit code as the application has not exited yet. Use winscp.com instead, what is a console application.
https://winscp.net/eng/docs/executables
floschn

Scripting in Powershell

Hello,

I’m not sure if this is a Bug or I am missing something here. But maybe some could help me with my problem. I like to script and FTP Transfer from Powershell. So far everything works fine but not the exit codes.

For a small test I made 2 commad scripts one that works and one that will fail. When I do let them run from batch the exit codes return fine.

winscp.exe /console /script=test1.txt /log=ftp.log
ErrorLevel 0

winscp.exe /console /script=test2.txt /log=ftp.log
ErrorLevel 1

pause
Press any key to continue . . .


But from Powershell I always get an “0” as return code.

.\test1.ps1
0
0

Code of powershellscript:

.\winscp.exe /console /script=test1.txt /log=ftp.log

$LASTEXITCODE
.\winscp.exe /console /script=test2.txt /log=ftp.log
$LASTEXITCODE


ftp.log shows following line:
. 2014-01-15 12:24:51.561 Script: Failed
. 2014-01-15 12:24:51.561 Script: Exit code: 1
. 2014-01-15 12:24:51.561 Disconnected from server
< 2014-01-15 12:24:51.567 226 Closing data connection

Exit Codes from Powershell:
https://devblogs.microsoft.com/powershell/errorlevel-equivalent/
i tried by myself with ping and the sc command. On both the exit codes worked.
Has anyone got this working on WinSCP or does have an idea how to sovle this. (i don't want to use batch)