0

I want to schedule a task that for each file in a specific local directory deletes a file with the same name on a remote server's directory.

On the command I run this

for  %f in (*) do start winscp /command "open ftp://user:[email protected]/"   "rm %f" "close" "exit"

and it works

but when I run it as a scheduled task and starting the cmd.exe program and passing in the following argument for %f in (*) do start winscp /command "open ftp://user:[email protected]/" "rm %f" "close" "exit" it doesnt work

what is my problem?

Meir
  • 103
  • 2
  • 6
  • 'it doesn't work" - Can you be more specific? – Ramhound Jan 06 '21 at 21:40
  • Does this answer your question? [Command works from command line, but not from Task Scheduler](https://superuser.com/questions/629554/command-works-from-command-line-but-not-from-task-scheduler) – Martin Prikryl Jan 07 '21 at 07:32
  • Please kindly check if the following thread was helpful to you:[How to pass an argument to a Windows Scheduled Task with spaces in it](https://superuser.com/questions/270643/how-to-pass-an-argument-to-a-windows-scheduled-task-with-spaces-in-it) – Sunny Jan 07 '21 at 08:13

1 Answers1

0

You need to add "/c" at the beginning of the arguments:

/c for  %f in (*) do start winscp  /command "open ftp://user:[email protected]/"   "rm %f" "close" "exit"

So the complete command would become as follows:

cmd.exe /c for  %f in (*) do start winscp  /command "open ftp://user:[email protected]/"   "rm %f" "close" "exit"

For more details, see also this thread: https://stackoverflow.com/a/5047185/5538923 .

marcor92
  • 116
  • 2
  • Good, but now I scheduled the task. Each time the task runs it opens a cmd promp window. Can I stop this? @marcor92 – Meir Jan 08 '21 at 02:37
  • @Meilech in order not to show the cmd prompt window, you can try to remove the "/command" from your arguments. For more details see here: https://winscp.net/forum/viewtopic.php?t=10977 and here: https://winscp.net/eng/docs/commandline#scripting . – marcor92 Jan 08 '21 at 12:09