ftp automation

ScriptFTP

The professional tool to automate FTP, SFTP, FTPS and schedule FTP batch jobs

The forum is now read only. Please, go to the the main ScriptFTP website if you need help.
Need help writing a script? Have any question about ScriptFTP?
What is the proper syntax for passing ScriptFTP GETLIST $item variables to local MS-DOS commands using the ScriptFTP EXEC command?

In my case, I want to upload a list of files from a local directory, then move each file to a different local directory only if it uploaded successfully.
FTP Script
  1. # Retrieve the local file listing
  2. $result=GETLIST($list,LOCAL_FILES,"*.*")
  3.  
  4. # If GETLIST failed stop the script
  5. IF($result!="OK")
  6.     STOP
  7.  
  8. # For each file in $list...
  9. FOREACH $item IN $list
  10.     # Upload the file
  11.     $result=PUTFILE($item)
  12.  
But I don't know where to go from here. I know that I need to something like
FTP Script
  1. EXEC('move . . .')
but I don't know how to use the $item variable so that my MS-DOS command executes FOREACH $item IN $list, moving each local file only after it uploads.

Any ideas or thoughts are welcome! Thanks!
You can use the dot (.) to concatenate text strings in order to build the EXEC parameter.
FTP Script
  1. FOREACH $item IN $list
  2.     # Upload the file
  3.     $result=PUTFILE($item)
  4.  
  5.     # If the file was successfully uploaded move
  6.     # it to C:\destination_dir
  7.     IF($result=="OK")
  8.         EXEC("move ".$item." C:\destination_dir")
  9.     END IF
If $item is for example test.txt the EXEC command parameter will be:
move test.txt C:\destination_dir
If you think that the file name may contain spaces, for example New text document.txt . You should take a look at the Remarks section of EXEC help topic:

https://www.scriptftp.com/d/ftp-miscellaneous-commands/exec