Archives
- July 2019
- January 2019
- November 2018
- August 2018
- July 2018
- February 2018
- November 2017
- October 2017
- July 2017
- June 2017
- May 2017
- April 2017
- January 2017
- December 2016
- November 2016
- August 2016
- January 2015
- December 2014
- March 2014
- April 2013
- December 2010
- November 2009
- September 2009
- June 2009
- March 2009
- February 2009
- November 2008
- October 2008
- August 2008
- July 2008
- January 2008
How to download a file from the web in ScriptFTP
29th December 2016Once 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 LOCALCHDIR("C:\Users\Carlos\Desktop\curl_downloaded_files") # 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.
Let’s see a complete script that downloads a file using curl and uploads the file to a FTP folder.
# Set the current local directory LOCALCHDIR("C:\Users\Carlos\Desktop\curl_downloaded_files") # Download the file EXEC("C:\path_to\curl\curl.exe -O https://www.mydomain.com/thefile.zip") # Connect to the FTP site OPENHOST("ftp.myhost.com","myuser","123456") # Upload the file PUTFILE("thefile.zip") # Close the connection CLOSEHOST
We can also add some error handling to the script. In the case CURL fails downloading the file the script will stop
# Set the current local directory LOCALCHDIR("C:\Users\Carlos\Desktop\curl_downloaded_files") # Download the file $result=EXEC("C:\path_to\curl\curl.exe -O https://www.mydomain.com/thefile.zip") IF($result!="0") STOP END IF # Connect to the FTP site OPENHOST("ftp.myhost.com","myuser","123456") # Upload the file PUTFILE("thefile.zip") # Close the connection CLOSEHOST
If you search for tools like CURL you will find another popular one called WGET. CURL is way more powerful but WGET is simpler to use and also can download entire web sites. It can also be used from ScriptFTP just the same way, calling the EXEC command.