I'm currently in a bit of a pickle regarding some scripts I have been writing.
I am creating a script that uploads multiple files from an FTP server that my company owns, over to another FTP server that an associate company is in control of. I have successfully transferred files to and from each of the servers via an automated method of using the Windows built-in FTP client and Task Scheduler, but the problem this time is that the nature and sensitivity of the files being transferred means we need to move them over using SFTP, something that Task Scheduler isn't too keen on running properly.
Now I am aware that there is no native SFTP client for Windows, so after a bit of research I decided to install WinSCP and have a crack at automating a script that would do the process that is required.
Here is a little information to explain what the script does...
Server (A) is my FTP server. There is a folder on this server that has 6 files within it, all of which are overwritten once an hour, each day of the week. Lets call this Folder (A).
Server (B) is our associate FTP server. There is a folder on here that the files are to be transferred to. Lets call this Folder (B).
Once the transfer between Server (A) and Server (B) has been completed, the original files held on Server (A) need to be moved from their current location of folder (A) to an archive folder named Folder (A2) on the same server. This is to preserve the integrity of the files.
The script is written using WinSCP to perform the initial transfer. This is then fired using a Batch file that runs the script using certain parameters/commands, and then proceeds to perform an XCOPY command to move the files to an archive folder on the same server.
Now the batch file runs perfectly when firing it manually (double-clicking it), but when setting it up as a scheduled task in Windows Task Scheduler, it fails to run correctly. The task will run the XCOPY command perfectly as I can see the files moving on Server [A] from folder to folder, however it is not performing the WinSCP portion of the script. It's just skipping it out.
Here's the WinSCP script "testscript.txt"...
option batch abort
option confirm off
open sftp://username:password@serverbaddress -hostkey="ssh-rsa 2048 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"
option transfer binary
And the batch file that is running the SFTP commands...
"C:\Program Files (x86)\WinSCP\WinSCP.com" /script="testscript.txt" /ini="C:\Program Files (x86)\WinSCP\WinSCP.ini" /log="logscript.txt"
xcopy /y "C:\FTPRoot\FolderA\*.xml" "C:\FTPRoot\FolderA2\"
Can anyone point out what may be wrong here?
I have already tried the solution in THIS ARTICLE
, however It hasn't seemed to work for me. Even forcing the scheduled task to run by right-clicking it and choosing 'run' gives me the same problem, so there is obviously something that Task Scheduler doesn't like about the batch file.
Any help is greatly appreciated! I'm getting dizzy going round in circles this much...