Hi,
How can I delete remote files from the ftp server after downloading them? I have 50 directories and within each directory there are 2 subdirectories in which the files that I need (to download then delete) exist. Here is what I have thus far...
So my question is; how do I add the "SUBDIRS" command to the "DELETEFILE" command? Is this possible? When I run the script above it downloads all files appropriately; however when it gets to the "DELETEFILE" command, it returns the following...
How can I delete remote files from the ftp server after downloading them? I have 50 directories and within each directory there are 2 subdirectories in which the files that I need (to download then delete) exist. Here is what I have thus far...
FTP Script
- # Connect to FTP server
- # Go to D:\mylocaldirectory
- # Get all the files in the FTP server
- #Change Remote Directory
- # Delete all files after download
- # Transfer finished, close the connection
DELETEFILE("*.*")If I add the "SUBDIRS" command I get the following error...
No remote file matches the wildcard
Running D:\Program Files\ScriptFTP\templates\download.ftp
***** Script error on line 20, column 17: ")" expected
DELETEFILE("*.*",SUBDIRS)
^
The DELETEFILE command does not accept SUBDIRS. If you want to remove a
complete directory tree try RMDIR instead.
I suggest you to check the result of GETFILE before deleting the remote files. Something like:
If you have always two levels of subdirectories I think you can even try something like the example download_and_delete.ftp (http://www.scriptftp.com/examples.php?go=download_and_delete.ftp) of the script samples. The script will be a bit more complex but is also more powerful because it download, checks and deletes each file separately, not the complete directory tree.
complete directory tree try RMDIR instead.
I suggest you to check the result of GETFILE before deleting the remote files. Something like:
If you have always two levels of subdirectories I think you can even try something like the example download_and_delete.ftp (http://www.scriptftp.com/examples.php?go=download_and_delete.ftp) of the script samples. The script will be a bit more complex but is also more powerful because it download, checks and deletes each file separately, not the complete directory tree.
liked Script FTP? Try our other product Email Parser
Thanks, but I don't need to delete the actual directory or folder only the files within the folders (doesn't RMDIR remove the entire directory or folder)?
If SUBDIRS works with DELETEFILE, how do I do it? The error below is always generated when using SUBDIRS with DELETEFILE. Am I using improper syntax? I tried the following code
But I always get the following error
If SUBDIRS works with DELETEFILE, how do I do it? The error below is always generated when using SUBDIRS with DELETEFILE. Am I using improper syntax? I tried the following code
FTP Script
Running D:\Program Files\ScriptFTP\templates\download.ftpTHANKS!
***** Script error on line 20, column 17: ")" expected
DELETEFILE("*.*",SUBDIRS)
^
<me> The DELETEFILE command does accept SUBDIRS.Oh, sorry. I typed it wrong. The DELETEFILE does not accept SUBDIRS.
<you> I don't need to delete the actual directory or folder only the files within the foldersOk, I think I got it. I've written a script and pasted below. Please let me know if it is what you want:
FTP Script
- # Remote directory where the 50 subdirectories are located
- $remote_directory="/"
- # Local directory where the files are downloaded
- $local_directory="D:\test"
- # Connect to server, put your own settings here
- # If connection failed stop
- # Change the current local directory.
- # If LOCALCHDIR failed stop the script
- # Change the current remote directory.
- # If CHDIR failed stop the script
- # Once reached this point we are connected and ready
- # to browse the remote 50 directories with 2 subdirectories
- # in each one and a bunch of files in them ready for download.
- # Get the remote directory listing
- # it should retrieve 50 items.
- # If GETLIST failed stop the script
- # For each directory in $list...
- # Change current remote directory to that
- # subdirectory
- # Create a local directory with the same name
- # and change current local directory to it.
- # LOCALMKDIR may fail because it already exists
- # Get the subdirectory listing. It should get
- # two items
- # Change current remote directory to that
- # subdirectory
- # Create the local subdirectory with the same name
- # and change current local directory to it.
- # LOCALMKDIR may fail because it already exists
- # Get the file listing
- # Download the file
- # If the file has been succesfully downloaded
- # delete the remote copy. If not stop the script.
- # Return to parent directory
- # Return to parent directory
liked Script FTP? Try our other product Email Parser
PERFECT!
I remarked out the create directory bit (the local directories always remain in-tact) - and it has been running for days without fail.
THANK YOU!!!
I remarked out the create directory bit (the local directories always remain in-tact) - and it has been running for days without fail.
THANK YOU!!!
- All times are UTC -