ftp automation


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?

I'm trying to make a simple download and delete script, the examples shown online are slightly different.

I'd like to log into the ftp site
navigate through some folders
copy all files with a mask blabla*.bak etc.
paste in a local folder
delete files from ftp

no need for error checking. This should be pretty simple but I'm struggling to get it working properly.

Really appreciate any help

Hello Nick,

I've written this small example. It is based on the script download_and_delete.ftp you can find on the Script library section but it is modified according to what you said. I hope it helps:
FTP Script
  1. OPENHOST("ftp.myhost.com","mysuer","mypassword")
  3. # go to folder 1
  4. CHDIR("/folder1")
  5. LOCALCHDIR("C:\users\carlos\desktop\folder1")
  6. GETLIST($list1,REMOTE_FILES,"blabla*.bak")
  7. GETLIST($list2,REMOTE_FILES,"blabla2*.txt")
  9. # Append the lists. Lists are just text string with
  10. # file names separated by "|"
  11. $list=$list1."|".$list2
  13. # For each file in $list...
  14. FOREACH $item IN $list
  15.  # Download the file
  16.  $result=GETFILE($item)
  17.  # If the file has been succesfully downloaded
  18.  # delete the remote copy. If not stop the script.
  19.  IF($result=="OK")
  20.  DELETEFILE($item)
  23. # go to folder 2
  24. CHDIR("/myfolder/folder2")
  25. LOCALCHDIR("C:\users\carlos\desktop\myfolder\folder2")
  26. GETLIST($list1,REMOTE_FILES,"blabla*.bak")
  27. GETLIST($list2,REMOTE_FILES,"blabla2*.txt")
  29. # Append the lists. Lists are just text string with
  30. # file names separated by "|"
  31. $list=$list1."|".$list2
  33. # For each file in $list...
  34. FOREACH $item IN $list
  35.  # Download the file
  36.  $result=GETFILE($item)
  37.  # If the file has been succesfully downloaded
  38.  # delete the remote copy. If not stop the script.
  39.  IF($result=="OK")
  40.  DELETEFILE($item)
  43. # Close the connection
Thanks that's really helpful. It works well.

if I just have 1 file type to copy and delete I guess I can remove the 2 lines....



thanks again
Yes, correct. You can remove that lines. It should look like this:
FTP Script
  1. GETLIST($list1,REMOTE_FILES,"blabla*.bak")
  3. # For each file in $list1...
  4. FOREACH $item IN $list1
  5. # etc..