Uploading only the files created or modified in the last 7 days

29th January 2019


The following script shows how to upload to the FTP server the files from the last 7 days. If a file is more than 7 days old it will be ignored.

Note that this example does not work with subfolders.


read more …


How to download the files created in the last 48 hours

21st November 2018


Date and time operations in ScriptFTP are something that we often get asked in the tech support email. ScriptFTP stores time ranges in seconds and this is sometimes counter-intuitive if you want to do date and time operations like checking how old a file is. Fortunately, this type-free approach in the ScriptFTP language also makes the syntax easier to understand.

Well, let’s go to the actual topic of this blog post: How you can check if a file in the FTP site was created in the last 48 hours and if so download it. Here is the script. The comments in it are very self-explanative:

read more …

How to delete all the sub-directories in a directory

12th August 2018

Recently we received a question from a customer that was using a set of IP cameras and a central FTP server where the cameras stored their recorded videos. As the cameras generate a lot of data they wanted to schedule an FTP script that deletes all the sub-folders of a given folder.


The script is pretty straightforward, all it is needed is to use GETLIST to retrieve the list of sub-directories, then use FOREACH and RMDIR to delete each one:


read more …


How to check if a file exists in the FTP server

22nd November 2017

This blog post shows how to check if a file exists in the FTP server. The shown example tries to download a file only if it exists but if it does not exist it creates an empty file locally. The filename here is EXAMPLE.txt but it can be any other name.

Beware that this script does not go through all the directory tree in the FTP server searching for the file. It only checks one directory (/remotedir) and does not go through subdirectories. This is done getting the file list first with GETLIST and then we use FOREACH to compare every file name we got in the previous step with the text string “EXAMPLE.txt”:


# Connect to the server
# Get the list of remote files
 GETLIST($my_remote_files, REMOTE_FILES)
# We will save in this variable whether or not the file exists
# Go one by one through the list of remote files
 FOREACH $file IN $my_remote_files
     END IF

read more …


How to get the latest file out of each folder

6th November 2017


Recently a user has asked via the website chat (the icon at the lower right corner) an interesting question:


I am looking for scriptable FTP to do the following… I have an FTP location with many folders(about 500.) I would like to get the latest file out of each folder. Or better yet, get the latest file out of a list of folders. Can your program do this recursive FTP?


The answer is yes. It is possible to get the latest file out of a list of folders. It is not a simple script but it is definitely possible. The steps needed are the following:

  • Store the list of remote folders where you want to look in a variable. Each item of the list is separated by the | character.
  • Use the FOREACH loop to run a set of FTP commands for each folder defined in the previous step
  • Use the command GETLIST to retrieve the list of files in a folder.
  • Use again the FOREACH loop to run a set of FTP commands for each file.
  • Retrieve the last modification time of the remote file using GETFILETIME and save it in a variable.
  • If it is the most recent modified time we have seen store also the path of the file.
  • Once all the files are processed go the next folder of the list.
  • When we have reached the end of the folder list download the file using the path we have saved in a variable.
The only drawback of this script is that it only handles the files in a folder directly, not files stored in subfolders. In other words, it does not go through a tree of subdirectories. But there is a workaround to this limitation: You can add the subfolder to the folder list as /myfolder/mysubfolder.
The full script and its output is:

read more …


How to create a local folder using the current date

23rd October 2017

Dates can be written in multiple ways, not only because of the language used (English, Spanish, German…) but also within the same language we can write a date in many different ways. For example in English, we can write it as “20 October 2017”, 20/10/2017, 10/20/2017 etc.

In ScriptFTP the most common formats of dates are available in the GETTIME command but sometimes you need to retrieve the date or time components separately (month, day, year, hour…) and build your own expression of a date or time. In this example, it is shown how to build a date expression without spaces and using a three letter month, for example “20Jan2017”. We will then use it to create a local directory.


read more …


How to download a file from the web in ScriptFTP

29th December 2016
ScriptFTP has commands to retrieve files from FTP sites only but it can also download files from the web (HTTP/HTTPS) using an external tool like CURL. You can download it going to this page. The Windows version of CURL is almost at the bottom of that page.
Once you have downloaded it you need to place curl.exe in any folder and call it from ScriptFTP using the EXEC command this way:
# Set the current local directory
# Call curl
EXEC("C:\path_to\curl\curl.exe -O https://www.mydomain.com/thefile.zip")
If you browse the CURL website or run “curl.exe –help” you will notice the big amount of options and switches it has. It is a very versatile tool that not only downloads file from websites, it is also capable of automating form filling, HTTP authentication etc. For example, if the web browser prompts to enter an user name and password you can tell curl to login this way:
# Download a file using HTTP authentication
EXEC("C:\path_to\curl\curl.exe --user johndoe:thepswd -O https://www.mydomain.com/thefile.zip")
Note that HTTP authentication is not the kind of authentication you commonly find when going to web sites like yahoo mail, gmail etc. These are just HTML forms. You can identify HTTP authentication when the browser asks for the login in a very spartan pop-up window on top of the web browser.

read more …


Handling file dates and time spans

13th December 2016

The ScriptFTP scripting language does not have data types (as most scripting languages) and dealing with anything which is not plain text requires some kind of tricks. This happens with file lists as we have seen before, dates and time spans suffer the same limitation. This post covers how these data types are handled in ScriptFTP.

read more …

Lists in ScriptFTP

24th November 2016

ScriptFTP, as many script languages, does not have data types. This makes the script language and its syntax a lot easier to learn but not as powerful as others. Think of it as being “not so descriptive” and “less complex”. The drawback, in practice, is that you cannot handle things like “lists”,”sets” etc. Everything is a plain text string and you need to deal with this limitation to get the things done.

Regarding to the lists. How can the FTP script handle a list? There is a shortcut:

$my_list = "my_item_number_1|my_item_number_2|my_item_number_3"
FOREACH $item_name IN $my_list

Running the script you get:



read more …