This is an old revision of the document!
Debugging WinSCP scripts and batch files
This article summarizes useful techniques when debugging non-working WinSCP scripts and batch files.
Session Logging
When using WinSCP scripting, even if it works currently, you always should have session logging enabled. To enable logging, add /log
switch to WinSCP command-line.
winscp.com /ini=nul /script=script.txt /log=script.log
The log file includes useful information for most problems you can encounter with WinSCP.
Inspecting Console Output
In rare case when WinSCP fails even before a session starts, the session log file is not produced. In this case the errors will display on WinSCP console output.
If you run WinSCP or wrapper batch file directly from Windows Explorer, the console window will close very quickly, so you might not be able to read the output.
When debugging script, it always better to use a console window, like Windows Command prompt or PowerShell. Additionally, use winscp.com
console interface tool to run the script, as it (contrary to winscp.exe
) outputs to the same console window, where it was started from.
Alternatively, when using a batch file, you can add pause
command to its end to prevent the console window from closing immediately.
winscp.com /ini=nul /script=script.txt /log=script.log pause
Further Reading
- Why are some WinSCP scripting commands specified in a batch file not executed/failing?
- Debugging transfer task running in Windows Scheduler, SSIS, or another automation service
- Why WinSCP does not work in a new environment (operating system, machine, user account, network), when it works for me in a different environment already?
- Why I cannot connect/transfer using script, when I can using GUI (or vice versa)?