I noticed that if I use the putfile command, and there's a local file with the same name as a file already in the remote directory that I'm uploading to, the file gets overwritten. Is there a way to check that or auto-rename the file if there's a file with that name already in the directory?
Hello,
You have to check first if the file already exists in the FTP site, if it exists upload it with a different file name. For example:
If you are uploading files and directories it's far more complex. This example only works if you are not using the SUBDIRS parameter in PUTFILE.
The PUTFILE2 command in the example is a command yet to be included in the mainstream version of ScriptFTP. It's used to upload a file with a different name. If you get a syntax error at this line try downloading the latest build of ScriptFTP from here:
http://www.ScriptFTP.com/ScriptFTP_devel_setup.exe
You have to check first if the file already exists in the FTP site, if it exists upload it with a different file name. For example:
Code: Select all
OPENHOST("127.0.0.1","carl","123456")
# Change current local directory
LOCALCHDIR("D:\test")
# Change current remote directory
CHDIR("/myremotedir")
# Retrieve the local file list
GETLIST($local_file_list,LOCAL_FILES)
# For each file in the current local directory
# check if it already exists. If it does not
# exist upload using the same file name,
# if it already exists append the current
# date-time to the filename and upload it
FOREACH $local_file IN $local_file_list
# check if it already exists
GETLIST($list,REMOTE_FILES,$local_file)
IF(COUNTELEMENTS($list)>0)
# It already exists, upload it with a different name
PUTFILE2($local_file,GETDATE(FORMAT1).$local_file)
ELSE
# It does not exist, upload with the same name
PUTFILE($local_file)
END IF
END FOREACH
CLOSEHOST
If you are uploading files and directories it's far more complex. This example only works if you are not using the SUBDIRS parameter in PUTFILE.
The PUTFILE2 command in the example is a command yet to be included in the mainstream version of ScriptFTP. It's used to upload a file with a different name. If you get a syntax error at this line try downloading the latest build of ScriptFTP from here:
http://www.ScriptFTP.com/ScriptFTP_devel_setup.exe
liked Script FTP? Try our other product Email Parser