That was typical once again. A friend was looking on the JTL wiki and saw a script for downloading a file from the web server via FTP to the local computer. Only the script somehow doesn’t seem to do what the user expects. Promptly comes the post in the JTL user community with the friendly hint that I can surely solve the problem. How do people come up with this? Okay here comes the solution.

There are several solutions for automatic download via FTP. For one thing, we could write ourselves a SKript using WinSCP, which is not a bad thought. The second approach is based on the JTL-Wawi Wiki a batch file that executes a FTP script. As long as we only do the download on a Windows client, the batch file is quite sufficient. The situation is slightly different if we want to run the download directly on a Windows 2012 R2 or Windows 2016 server. An error occurs here despite the firewall being open. That’s why we use the WinSCP tool there, which we then start via task scheduling.

First of all, we need a directory on our server or Windows PC where we will place the necessary batch files and which will serve as the target for our download. For this we create a folder somewhere, preferably in the root of a partition, e.g. C:Download. In this folder we create two files with the editor. One with the meaningful name download.bat and the other we call ftpdownload.ftp. In any case, we should make sure in advance that the file name extensions are displayed! The whole thing will look something like the following three screenshots.

Once we have created the files, we can start “scripting”. First we create the script for the FTP download and open the file ftpdownload.ftp in the editor.

In order to create our download script, we now need the following information:

  1. The domain where the data is located, e.g. mydomain.com
  2. The FTP username, e.g. webmaster
  3. The secret password of the FTP user, e.g. P@ssw0rd
  4. The path to the file on the web space, e.g. httpdocs/download
  5. The filename of the file we want to download, e.g. test.txt

From this information we now build the following script:

open meinedomain.de
webmaster
P@ssw0rd
bin
lcd C:download
cd /httpdocs/download
get test.txt
bye

In the script you now only have to replace my sample data with yours.

Now we edit the download.bat, which we use to call ftpdownload.ftp and initiate the actual download. Here we enter the following beautiful 4-liner:

@echo off
echo --- starte FTP-Transfer….
ftp -s:ftpdownload.ftp
echo ---fertig.

For testing purposes, it is recommended to add the Pause command at the end, as you can see from the screenshot. If you want to execute the file later automatically via the Windows task scheduler, you should remove this line afterwards.

Delta Whiskey, that’s about it. Now we can start our download.bat for the first time with a courageous double click.

When I test the script on a Windows server, after two minutes I get the error message “425 Unable to build data connection: Connection timed out”. What to hell is this. Even opening the ports on the firewall did not make my test server download the test file from my web server via FTP. Shit happens!

Only two alternatives remain. A PowerShell script or the use of WinSCP. I chose the latter, since dummies should also be able to cope with this tool. You can download WinSCP here: https://winscp.net/eng/download.php#download2

The installation of WinSCP is self-explanatory and I don’t think I have to explain it here after the start we have to connect to our FTP server.

Then we click on the menu item Session and there on Create Session URL/Code….

In the URL tab we activate the options Username, Password and then switch to the Script tab.

Here we click on the “Copy to clipboard” button and then open the Windows Editor.

We paste the text from the clipboard into the new text file and delete the lines “# Your command 1” and “# Your command 2”. For this the line get /[Pfad zur Datei]/[Dateiname] [lokales Zielverzeichnis][lokaler Dateiname] one. The whole thing should look like this get /httpdocs/test.txt C:Downloadtest.txt

We save the file as ftpdownload.txt in the Download directory and call it from the command prompt. For this we change there to the installation directory of WinSCP C:Program Files (x86)WinSCP and enter this command winscp /script=”C:Downloadftpdownload.txt”.

The whole thing can now be put into a simple task in Computer Management Task Scheduling and then the file will be downloaded from the server once a day. Here I must pay attention only to the fact that I select under program/script the WinSCP.exe and with arguments add /script=”C:Downloadftpdownload.txt” deposit. Ready is the automatic FTP download.

  • 0/5
  • 0 ratings
0 ratingsX
Very bad! Bad Hmmm Oke Good!
0% 0% 0% 0% 0%

Haben Sie Fragen oder brauchen ein individuelles Angebot? Zögern Sie nicht, uns zu kontaktieren.


    eBakery requires the contact information you provide to contact you regarding our products and services. You can unsubscribe from these notifications at any time. For information on unsubscribing, as well as our privacy practices and commitment to protecting your privacy, please see our Privacy Policy.*.

    Related Posts

    Leave a Comment

    Hat dir der Artikel gefallen?

    Dann melde dich doch zu unserem Newsletter an!

    Neben unseren Blog Themen informieren wir dich darin regelmäßig zu neuen Features und Tutorials