I have a Windows cmd batch file that should retrieve listing of files that are on an FTP server via sFTP using PuTTY PSFTP exe and use that for further processing. The cmd is:
echo ls | psftp -l myusername -pw mycomplexpwd FTPServerHostname > C:/Users/myuser/Desktop/ls.txt
It is supposed to output the listing in ls.txt
file that I use in other scripts. When running as a normal user, I get the listing alright. However, when using Task Scheduler and schedule the script as SYSTEM
user, I get only this in the output file:
Remote working directory is /
psftp> quit
I guessed that there is a problem in the pipe |
usage or something so I also tried using this syntax but also same output:
psftp -l myusername -pw mycomplexpwd FTPServerHostname < C:/Users/myuser/Desktop/lscmd.txt > C:/Users/myuser/Desktop/ls.txt
What could be causing the problem when scheduling the job as SYSTEM instead of my user? And how to get the listing as SYSTEM? Note that when running the script as Administrator (right click - Run as Administrator) I get the listing alright, the problem is only when using task scheduler and schedule the task as SYSTEM.
OS is Windows Server 2012 R2.