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?
Hello *,

I must make an FTP-Access to an remote Server.
The FTP-Provider provide for a normal File a separate .ok-File. If this .ok-File exist it´s "safe" to download the normal file, e.g:
File1.txt
File1.txt.OK

After the download is ended normally, both files should be deleted.
How can I handle this with scriptFTP?

Kindly regards
Marc
Hello Marc,

There is a script sample at http://www.scriptftp.com/examples.php?g ... delete.ftp that performs a very similar task. All you have to do is to find this chunk:
Code: Select all# Get the remote file listing, store it in $list $result=GETLIST($list,REMOTE_FILES,"*.txt")  
And change it to this:
Code: Select all# Get the remote file listing, store it in $list $result=GETLIST($list,REMOTE_FILES,"*.OK")  
If you need further assistance don't hesitate to post a message here.
Hello,

thank yout for the help.
But If I change it to:
Code: Select all$result=GETLIST($list,REMOTE_FILES,"*.OK")
only the OK-Files will be downloaded. I tested it with these functions:
Code: Select all# For each file in $list... FOREACH $item IN $list_ok # Download the file $result_ok=GETFILE($item) # If the file has been succesfully downloaded     # delete the remote copy. If not stop the script. IF($result_ok=="OK") DELETEFILE($item) ELSE STOP END IF END FOREACH FOREACH $item IN $list_txt $result_txt=GETFILE($item) IF($result_txt=="OK")  DELETEFILE($item) ELSE  STOP END IF END FOREACH
This works great, but FTPScript will download all files, generally! But I have the problem, that I have to wait for the OK-File to download the DATA- and the OK-File.
So in this case I must have a function like:

if $item.OK exist then download $item and $item.OK

Is this possible?

Greetings Marc
Hello *,

I tested it now wiith following function:
Code: Select all$result_ok=GETLIST($list_ok,REMOTE_FILES,"*.ok") $result_txt=GETLIST($list_txt,REMOTE_FILES,"*.txt") IF ($list_ok==$list_txt)     GOTO :download  ELSE     PRINT("NOT EQUAL")     GOTO :end END IF
So "Not Equal" is in that case the normal statemen, because the file will differ in the extension (file1.txt, file1.txt.ok). I don´t know the filenames, only the extension!

Kindly regards
Marc
Hello Marc,
So "Not Equal" is in that case the normal statemen, because the file will differ in the extension (file1.txt, file1.txt.ok). I don´t know the filenames, only the extension!
Ok. Now I understand what you want. Install ScriptFTP again from this URL:

http://www.scriptftp.com/ScriptFTP_3_0_setup_devel.exe

I've just added to ScriptFTP two new commands (TEXTCUT and TEXTLENGTH) that are used to remove the trailing ".OK" from the variable that contains the file name. This new value is used to download the corresponding file.
Code: Select all# This script piece gets the remote file listing and downloads a # file only if it exists also a remote file with the same file name # with a trailing ".OK". For example, for this remote file listing: # # 1234.txt # abcd.zip # 1234.txt.OK # # Only 1234.txt along with 1234.txt.OK will be downloaded and # deleted from the remote site. # $result=GETLIST($list,REMOTE_FILES,"*.OK") IF($result!="OK")     STOP END IF # For each file in $list... FOREACH $item IN $list         # get the number of characters of the file name     # ***** Warning! The TEXTLENGTH command does not     # work in the 3.0 version available under the download     # section  of the website. Read the complete conversation.     $item_number_of_characters=TEXTLENGTH($item)     # Remove the ".OK" from the file name     # ***** Warning! The TEXTCUT command does not     # work in the 3.0 version available under the download     # section  of the website. Read the complete conversation.     $file_to_download=TEXTCUT($item,1,$item_number_of_characters-3)     # Download the file     $result=GETFILE($file_to_download)     IF($result=="OK")         # Download successful, delete the remote file         DELETEFILE($file_to_download)     ELSE         STOP     END IF # Download also the file with the trailing ".OK" $result=GETFILE($item) IF($result=="OK") # Download successful, delete the remote file DELETEFILE($item) ELSE STOP END IF END FOREACH
Please, post any thought or result you may have.
Many, many, many thanks. That´s exactly what I need. With your Example-Script it works perfectly!

Kindly Regards
Marc
I just got ScriptFTP today and posted a request on the Wanted Features forum, but this looks like server code to me.
I can do code in this form but I am running it on my XP machine to make sure I always have the files on the server on my machine.

Is this an Advanced Server Side .ftp Coding Format?
Or can I use it on my home XP end?

It's the variables that are throwing me off.
All I know is, if I can program sFTP on my end based on more than just exact date, like on file size, and make some logical IF/THEN decessions that would be great.