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?
Difficult to find a title for this one.

This is the scenario.

I have a server, were users upload files (with an custom program we wrote).

When the file is uploaded, our program also uploads a 'META' file with some additional info, same file-name, other extension.

So to files are uploaded :

file.ext
file.META

The .META file is always the last to be uploaded.

Now, I'm looking for a way to only start downloading and deleting the files , only if the .META file is there.
I can't get it into a script.


in short :
- check FTP for .META files
- if a .META file is there, download & delete the metafile, and corresponding file, but make sure the corresponding file is downloaded first, and the META file last.



Thanks in advance.

Erwin
Hi Erwin,

Thanks for posting here. This one was a bit tricky to write. I guess it will be useful for some advanced users:

[scriptftp="ftp_transfer.ftp"]# Connect to server
OPENHOST("myftpserver.com","test","test")

# set current local directory
LOCALCHDIR("C:\Path\To\TEST")

# set current remote directory
CHDIR("/test")

# get a list of all the meta files in the server
GETLIST($list_meta_files,REMOTE_FILES,"*.META")

# for each meta file
FOREACH $meta_file in $list_meta_files

# Get a text string containing the file name without the META extension
$meta_file_without_extension = TEXTCUT($meta_file,1,TEXTLENGTH($meta_file)-5)

# Check if there are other files with the same name
GETLIST($l,REMOTE_FILES,$meta_file_without_extension."*")

# If there is more than one file matching this criteria means
# that we have other files with the same name and other
# extension different than META
IF(COUNTELEMENTS($l)>1)
# Download the files except the META
FOREACH $file in $l
IF($file!=$meta_file)
GETFILE($file)
END IF
END FOREACH

# Download and delete the meta file
GETFILE($meta_file)
DELETEFILE($meta_file)
END IF

END FOREACH

CLOSEHOST[/ScriptFTP]
Thanks, i'll check this first thing tomorrow.

As far as I can sse, this is exactly hat im looking for.

I'll post the result over here when i did the test.
I ran the script for several dys now, and it does exaclty what is has to do.

Thank you !
Great :)

Thanks for posting here the update