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.
Missing any feature or command? Post your ideas here. Suggestions are welcome.
I have written a script, using your samples, to copy files from a folder to an ftp site and then delete the source file if the upload is successful (http://www.scriptftp.com/examples.php?g ... delete.ftp). Works well. I now, however, need to alter that script by allowing for folders with files in them. I can do the PUT w/ subdirs and can delete *.* from source path at end but need to delete all once a successful PUT has been determined. In other words, how do I add the folders to the del routine?
In other words, how do I add the folders to the del routine?
To do that you have to know first the maximum levels of subdirectories you expect to have from the root folder. Once you know that all you have to do is to nest as many FOR EACH blocks as you need. It sounds a bit complex so let me know how many levels you expect to have and I'll write an example.
Unfortunately, it will vary. Sometimes 1, sometimes 4, sometimes none.
Well, if this is the case I think that there is no simple way to accomplish that task. I'll move this thread to the feature request forum.

I think that the best way to make ScriptFTP capable of upload a complete tree and delete only the files that were successfully uploaded is adding support to functions or procedures. Just like other programming languages already do. It must be something like:
Code: Select all# # WARNING: This code will not work. # It's only a sketch of how ScriptFTP could have the requested capability. # # Connect to the FTP server OPENHOST("192.168.23.32","myusername","mypassword") UploadDirectoryAndDeleteContents("C:\directory_filled_with_files_and_subdirs") # Close the connection CLOSEHOST FUNCTION UploadDirectoryAndDeleteContents($dirname)     # Change current local directory     LOCALCHDIR($dirname)     # Create the directory in the FTP site     MKDIR($dirname)     # Change current remote directory     CHDIR($dirname)     # Retrieve local file listing     $result=GETLIST($list,LOCAL_FILES)     # If GETLIST failed stop the script     IF($result!="OK")         STOP     END IF     # For each file in $list...     FOREACH $item IN $list         # Upload the file         $result=PUTFILE($item)         # If the file has been succesfully uploaded         # delete the local copy of the file         IF($result=="OK")             EXEC("del ".$item)         END IF     END FOREACH     # Retrieve the directory listing     $result=GETLIST($list,LOCAL_DIRECTORIES)     # If GETLIST failed stop the script     IF($result!="OK")         STOP     END IF    # For each subdirectory     FOREACH $item IN $list         # Call this function again and go deeper         # in the directory structure         UploadDirectoryAndDeleteContents($dirname)         # If no error ocurred dirname is now empty         # delete it         EXEC("rmdir ".$dirname)     END FOREACH     # Return to the parent local directory     LOCALCHDIR("..")     # Return to the parent remote directory     CHDIR("..") END FUNCTION  
Hi,

I hd to write an FTP import / export script supporting up to 5 directory levels in depth.
In addition the source directory structure had to be kept after a successful move and missing target directories had to be created automatically. Logfile mailing support included.
You can imagine that the script got rather complex and still has the 5 directory levels restriction.

I would be very happy to see something like PUTMOVE / GETMOVE or SYNCMOVE with options like SUBDIRS and in addition some optional switches to address automatic target directory creation and what to do with the directory structure after a successful move (leave or delete).

Ralph
Hi Ralph,

Yes, that script would be quite complex to write. I think that once functions are supported it will be possible to have a collection of functions in the script samples section that will perform that kind of complex tasks.

Note that ScriptFTP command set is intended to be as easy to understand as possible. I think that adding too many commands and/or options is not a nice solution.

Thanks a lot for the feedback.
Just my two cents on the matter...if you need to delete local directories with sub-folders and files you can use this command:

RD /S /Q C:\path

This will recursively delete files without prompting you, so be careful!

Works in 2000/XP and Vista!
Thanks for the contribution forest :)