That kind of problems are always caused by some difference between the environment provided by the scheduler to the program and the one at the command line.
You can use some utility as ProcessMonitor to see what is going on at the OS level.
In any case, post your code!
Comment on Re: Net::SFTP::Foreign and Windows Scheduler