Batch for loop in psexec command

1.1k views Asked by At

I'm trying to use a batch FOR loop inside a psexec. I need to make a script that offers me the possibility to choose the subfolders (I store the items in %list_of_items%) in %local_folder% that are needed to be copied with ncftpput on remote server. I cannot put the entire psexec inside the loop because I dont want to insert every time the password. The piece of code:

psexec \\remote_server -u DOMAIN\user cmd /c FOR %%i IN "%list_of_items%" DO ("ncftpput -f c:\folders\file_with_creds.cfg -R remote_folder/ %local_folder%/%%i")

Example I have:

  • %local_folder%\folder111

  • %local_folder%\folder222

  • %local_folder%\folder333

I choose to copy the items folder111 and folder333 so I store them in %list_of_items%. For every item in the list I need to run ncftpput to transfer to remote server the folder but doesnt work....

The error: "folder111" was unexpected at this time. cmd exited on remote_server with error code 1. Can you help me please to find what I'm doing wrong? Thank you.

0

There are 0 answers