Writing a Batch file and Script file to Push and Pull from the SFTP Server

Writing a Batch file and Script file to Push and Pull from the SFTP Server

Illuminate Education provides our districts and charter school organizations an SFTP server during their Implementation process. If you forgot your credentials for the server, you can contact our help desk at (949)-242-0343 or send in an email to [email protected]. Please provide your full name and district or character school organization. You should have all of the following information: server hostname, port number, username and password.

Our goal is to provide steps to pull and push files from the Illuminate SFTP server to the destination server, such as the third-party vendor's server. This guide targets users who are new to file-transfer protocols; there may be more efficient and more secure routes to carry out this task that we encourage districts.

Please note that Illuminate Education's support in this aspect is limited - this is generally considered the responsibility of the user.

Table of Contents

Important Considerations

  • Illuminate Support and Implementation Managers will not give your Illuminate SFTP credentials to a third-party.
  • We do not recommend giving your Illuminate SFTP credentials to a third-party.

Getting Started

Try logging into your SFTP server. We recommend the following free solutions:

Other methods:

  • Windows Command Line:
    • WinSCP (Windows)
    • PuTTY (Windows)
  • sftp command (OS X and Linux)

Put in your credentials for the Illuminate SFTP server based on how you decided to access your server.

You want to verify you can access your server. If you can connected and the directory and data looks familiar, you should be set. If you have problems connecting, please contact Illuminate Support to verify your credentials.

Manually Pulling Data (or pulling data once)

By default, we place your data in the directory data_extracts, in a folder named after the product, service or vendor. For example, an absence file for School Messenger may be found in data_extracts/schoolmessenger. You will want refer to the documentation provided by your SFTP software to verify. By default, most files get pushed into your Downloads folder on your desktop.

Automating Your Pull

The follow instructions focus on a Windows based solution. Solutions for other environments may be added at a later date based on demand.

The following commands can be used via a .bat script to automate (using an automation app such as Window Task Scheduler) files from our SFTP server into their local server. This script is made for a scenario where your local machine is running on Windows and attempting to pull a file from Illuminate’s SFTP server. Pay special attention to the forward/backward slashes in the commands below, as Windows uses backward slashes vs. Linux (our SFTP server) using forward slashes.

Step-by-Step Instructions

1. Download pSFTP

Download psftp from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. Please download the psftp.exe (the Windows installer) version.

2. Create a Batch File

This is the 1st file. Create a .bat (batch) file and copy/paste the following two lines into it. You can name this batch file anything you wish (ie. lunch_extract.bat, etc).

Line 1: Depending on where you downloaded and are storing the psftp.exe file, please specify the path to that file. For example, if I download the file into a folder at this path C:\myscripts\, then my first line would be:

1: set PATH=C:\myscripts\psftp.exe

Line 2: Referring to the SFTP credentials from Illuminate, replace the user_name and password fields in the following line below. At the end of the line, there is an option -b in which you specify what script file to run once connected to the sftp server. Rename the myextractionscript.scr if necessary (ie. lunch_extract.scr, mealtime_extract.scr, etc) or keep the generic myextractionscript.scr. A finished example would be:

2: psftp sftp.illuminateed.com -l "illuminate" -pw "ru1es" -b myextractionscript.scr

Your batch file should have the following two lines:

1: set PATH=C:\path\to\psftp\executable\file\psftp.exe
2: psftpsftp.illuminateed.com-l "user_name" -pw "password" -b myextractionscript.scr

3. Create a Script File

This is the 2nd file. Create a .scr (script) file and copy/paste the following 4 lines into it. Please be sure to name this .scr file according to what you stated in file 1 line 2 above. For example, in file 1 line 2 above, I specified "-b myextractionscript.scr", then I want to name this file "myextractionscript.scr”. The purpose of this file is to script the steps, once file1 has successfully logged you onto the server.

Line 1: The first line here is to specify the path, on your local machine/server, of where you want the files to download to. If for example, I want the file(s) to download to the path "C:\myscripts\lunch_data\", my completed line 1 would be:

1: lcd C:\myscripts\lunch_data\

Line 2: Specify the path on the sftp server where your file(s) are located. If you don't know, use your GUI sftp client (Cyberduck, Filezilla) to login and browse to your expected folder. You will find your file path in the URL somewhere. For example, if my file(s) are in this location (~/data_extracts/meal_time/), line2 would be:

2: cd data_extracts/meal_time/

Line 3: Specify what file(s) you wish to "get" and download back into your line1 path. If there are multiple files, use the asterisk: get *. Otherwise, for example, if I wanted to download one file (ie. mealtime.txt), line3 would be:

3: get mealtime.txt

Line 4: Quit/end the session.

4: quit

Your completed file should look have the following 4 lines, with directory paths as you spec’d:

1: lcd C:\path\where\you\want\to\save\to\on\your\local\machine
2: cd /path/to/file/you/want/to/download/on/sftp/server
3: get your_file_name.txt
4: quit

From here, you can do a few test runs by executing the batch script (file1). Simply double click the batch script and it should execute within Windows. If properly set, it should download the correct file(s) down to your machine, to that directory you specified in the “lcd” command. If it doesn't work or there are errors, troubleshoot.

4. Setup Windows Task Scheduler

Lastly, and once the scripts above are confirmed to be working, if you wish to set up automation, simply use Windows Task Scheduler to point to the batch file and schedule the times/dates/intervals. The Task Scheduler will execute that batch script at the time/date/interval that you've set up.

results for ""

    No results matching ""