# How to check if a file exists in the FTP server

22nd November 2017

Sometimes, it is needed to perform a given action depending on if a file exists in the remote side. In this case, we will show a small example that downloads the file 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$exists="no"

# Go one by one through the list of remote files
FOREACH $file IN$my_remote_files
IF($file=="EXAMPLE.txt")$exists="yes"
END IF
END FOREACH

Tags

# 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:

Tags

# 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.

Tags

# ScriptFTP 4.4

2nd October 2017

This is another small bug fixing release. Unless you have experienced problems installing ScriptFTP or use IBM zOS servers it is not worth applying this small update.

• Fixes on how RAWCOMMAND and FTP protocol NOOP command are sent to IBM zOS servers
• Fixed some WinHTTP Runtime errors during setup.
• Hot keys F5,F8 and ESC now works regardless of the element of the ScriptFTP window has the focus
• SILENT mode fixes. SYNC now shows the uploads/downloads even on silent mode as it was supposed to happen.

# ScriptFTP 4.3

17th July 2017

This is mainly a bug fixing release but it comes with the notable addition of a new separate command to set the SSH key file path:

– Added the command SETKEYFILE for SSH connections
– License key dialog now accepts line breaks. It is easier to enter a license key that is not a straight line (easier copy/pasting)
– The autorun window now has links to the ScriptFTP scheduler and the windows task scheduler.
– The output options window now shows a preview of the commands that will be added to the script with links to the web site.
– Fixed a bug in SYNC UPLOAD that happened when an existing remote file name is lowercased or uppercased.
– Fixed the link in the scheduled script dialog that pointed to the windows task scheduler.
– Fixed an issue that happened when subtracting dates. Resulted value was incorrectly formatted.
– “0 bytes/sec” is no longer shown in the status bar when the transfer is finished but ScriptFTP is jumping to another file.
– Fixed a bug in GETFILE2 and PUTFILE2 where file paths were not working properly.
SYNC now deletes the local temporary files it creates to know the clock time difference.

# ScriptFTP 4.2

1st June 2017

A new release is here. The changes are mostly bug fixes and setup enhancements:

– Setup now runs ngen.exe for faster program startup. What is ngen?
– Setup now opens ScriptFTP and the Lesson 1 of the FTP scripting guide after finishing the install.
– Setup shows the End User License Agreement (EULA) before installing. Nothing changed in the EULA but it seems that in some countries this is required before installing any software.
– Fixed a bug in RENAMEFILE command when using more than one dot when changing file extensions. For example: RENAMEFILE (“*.xml”,”*.xml.collect”)
– Fixed some weird quoting bugs in the EXEC command.
– When plain FTP is used a warning message is shown when OPENHOST is called.
– Fixed \$ in passwords. String expansion which was a hidden feature has been removed.
– If SETPORT is used SETPROTOCOL will not set the port automatically and will keep the port set beforehand.
– Fixed an error where SYNC was not checking if a directory to be uploaded was in the exclusion list

Tags

# How to set a FTP script to be run every X minutes

30th May 2017

From time to time a question like this is received in the tech support inbox:

I wanted to ask if you can set the sheduler every minute, thank you so much

In this case, the answer is straight: using the Windows task scheduler. Let’s see step-by-step how to configure it to run a FTP script every 1 minute:
1.- First, we create the scheduled script under ScriptFTP. This is a shortcut that will create for us a scheduled ScriptFTP task in the Windows task scheduler. We can also open directly the Windows the windows task scheduler and create the task manually but we will have to enter the ScriptFTP.exe path, the script path etc. Using ScriptFTP for this is easier:

# Running ScriptFTP on windows startup, logon etc

24th April 2017

More common questions:

Is that possible to run ScriptFTP automatically as a service everytime when Windows starts? If its possible to automate startup on logon?

Yes, this is possible. Instead of running it as a service you need to create a scheduled task from ScriptFTP and then go to the Windows task scheduler and edit its settings. Some screenshots below:

Scheduling ScriptFTP this way you can set it to be run not only at a given time but also at startup, at logon, on idle, when the user connects or disconnectes and also when the screen is locked or unlocked.

# A dump of random common questions

18th January 2017

I would like to obtain the encryption tool.

How can i start a scheduled task every hour at XX:55 and at startup of scriptFTP

You need to create a scheduled task within ScriptFTP and then open the windows task scheduler (usually under the control panel). Once you have located that task in the windows scheduler, open it and go to the “Triggers” tab. There you have to schedule the task to be run daily at, for instance, 00:55 and to be repeated every hour for one day.
To run a script file at the ScriptFTP startup you need to create a shortcut in windows that calls ScriptFTP wiith these parameters:

C:\Program Files(x86)\ScriptFTP\ScriptFTP.exe "C:\the_path\to_my_script\the_script_file.ftp"

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
EXEC("C:\path_to\curl\curl.exe -O https://www.mydomain.com/thefile.zip")
# Download a file using HTTP authentication
EXEC("C:\path_to\curl\curl.exe --user johndoe:thepswd -O https://www.mydomain.com/thefile.zip")