FTP batch file works from command line, but not scheduled task

3

I want a Windows scheduled task to execute an FTP batch file which will upload some files to my server. If I run the argument below from the command line then it executes successfully.

ftp -i -s:C:\<path-to-file>\ftp.dat

When I try and run this through a scheduled task it always gets to created task process and stays like this; it does not complete or fail. I have also tried this without the put commands and it still does it so it's not as if it is waiting to transfer the files.

I am creating the task through the task scheduler GUI on Windows Vista. Under the general tab I have run whether the user is logged on or not and run with highest privileges set.

Under actions it is set to run C:\\Windows\System32\cmd.exe.

And the argument is

ftp -i -s:C:\<path-to-file>\ftp.dat

The ftp.dat file looks like this:

open ftp.mysite.co.uk
myUsername
myPassword
put C:\<path-to-file>\file.xml
put C:\<path-to-file>\file2.xml
bye

I don't understand why this runs perfectly fine manually from the command line, but not from the scheduled task.

Tom smith

Posted 2013-08-08T15:23:57.027

Reputation: 141

Check out this post for some helpful tips that will likely help you resolve if you've not already: https://superuser.com/questions/1005192/problems-scheduling-a-task-on-windows7/1005216#1005216 I'll be happy to further help if you wish, just tag me back if so.

– Pimp Juice IT – 2017-09-23T18:51:48.903

Answers

0

My suggestion would be run a VBScript script in a scheduled task:

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "C:\Windows\System32\ftp.exe -i -s:C:\<path-to-file>\ftp.dat", , True

I've always had much more luck with scheduling VBScript scripts over trying to scheduled commands.

50-3

Posted 2013-08-08T15:23:57.027

Reputation: 3 779

0

It should work when you add "/c" as parameter for cmd.exe to run the ftp command:

C:\Windows\System32\cmd.exe
/c ftp -i -s:C:\<path-to-file>\ftp.dat

You can also try this 'whole' thing on the command line:

cmd /c ftp -i -s:C:\<path-to-file>\ftp.dat

Without "/c" it just opens a console within the console, note executing the command.

Acrklor

Posted 2013-08-08T15:23:57.027

Reputation: 111

Is there a reason to launch cmd when you can just run ftp directly? – James Snell – 2014-09-23T08:40:46.823

I had issues with different commands running directly which could be averted running it through cmd. Not specifically with ftp (and didn't try it), however I assumed he had similar reasons for this and wanted to change as little as possible in my answer. – Acrklor – 2014-09-23T09:00:31.033

0

It sounds like there is still a permissions or file access issue as when not running with a UI some parts of the environment are not available. It is likely that a file or path is not available since we don't know where goes...

The best thing to do is to log the output from ftp to see if there are errors. It would be useful to have anyway to review if there are any future problems like this:

ftp -i -s:C:\<path-to-file>\ftp.dat >c:\ftp.log

You could put the log file in the but it won't provide a log if you can't access that folder for some reason, so until you've ruled that out you're best to keep it in the root. Once you've ruled out that problem then you can move it to a more appropriate location.

James Snell

Posted 2013-08-08T15:23:57.027

Reputation: 348