0

I have a .bat file that:

executes WinSCP (calls a script txt) and transfers a file through SFTP. It also archives the file that was transferred.

My Problem is it works just fine when I double click the .bat file. BUT when I execute it in SQL Server agent job, it does archive the file but is not transffering the to the SFTP.

I get no error at all in the history of the job.

I feel it isnt executing the WinSCP or not opening the txt script. I checked permissions and it shows fine in all files and folders...

Checked FULL control for all users on all files and related folder. Tried checking my syntax.

"C:\Program Files\WinSCP\WinSCP.exe" /command "option confirm off" 
/console /script="C:\Program Files\WinSCP\LocalToRemote.txt"
Katherine Pacheco
  • 339
  • 3
  • 7
  • 24

1 Answers1

0

You should add /log=C:\path\to\winscp.log switch to WinSCP command line to see what's going on.

In a rare case the error is so fatal that even no log file is produced, you should capture WinSCP console output. You cannot do that with winscp.exe, you need winscp.com for that, and you should use it anyway.

"C:\Program Files\WinSCP\WinSCP.com" ^
    /log=C:\path\to\winscp.log ^
    /command "option confirm off" ^
    /script="C:\Program Files\WinSCP\LocalToRemote.txt" > C:\path\to\winscp.out

Until you show us the logs, I can only point you to WinSCP FAQ:
My script works fine when executed manually, but fails or hangs when run by Windows Scheduler, SSIS or other automation service. What am I doing wrong?

The most usual problem is the first one listed in the FAQ:

  • The script fails (or “hangs”), because the host key (SFTP or SCP) or certificate (FTPS, WebDAVS) is not known by the service’s account, and WinSCP fails (or asks for) its verification.

See also Debugging transfer task running in Windows Scheduler, SSIS, or another automation service.


The best what you can do it to have WinSCP GUI generate script/command-line/batch-file template for you, with all details needed for the script to be really portable.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992