Tutorial 1 - Upload file to server

Before reading this tutorial, please make sure you have CompleteFTP installed, and two users ('user1' and 'user2') created (see here).

This tutorial will implement a JSS process trigger that automatically transfers a file to a remote server, that has just been uploaded to your server.

Steps

  1. Open CompleteFTP Manager and select the Events tab. In Process Triggers panel click on the 'Add' button to add a new event.

  2. Choose the Upload file event.

  3. Check the "Trigger on success" box, then choose the JSS script and enter the script shown below:

    var ftp = new Ftp("myftpserver", "myusername", "mypassword");
    ftp.connect();
    ftp.upload(event.virtualPath, event.fileName);
    ftp.close();
    console.log("Upload complete");
    

    This script uses the Ftp class (a part of the JSS API). As you can see, three arguments are passed to the constructor: the IP address of the remote host, the user-name and the password. The connect() method is then called to connect to the server. Calling this method is optional, because the client will automatically connect when any other method is called, if it hasn't already connected. Calling it explicitly may be useful for error-handling. The upload method is then called to upload a file from the local virtual file-system, to the remote server. After uploading, the close() method is called to close the connection (again, this is optional as it happens automatically when the script completes).

    The process trigger should now look like this:

    Note that, if another FTP server is not available at this point, then for the purposes of this tutorial, the same server (i.e. 'localhost') can be used in the script. If you choose to do this, however, then you must make sure that this event doesn't trigger again, when the script uploads the file. You can do this by using the user filter to exclude the user, 'user2'. To do this, click the 'User filter' control, select 'user2' from the list and then check the 'Inverse' checkbox to the right.

    If you don't do this, then the upload operation in the script will trigger the upload event, which will execute the script, ad infinitum.

  4. When you've done scripting, click on 'Apply Changes' to save it and you can then start to use this event.

Testing your process trigger

Now your new JSS process trigger is ready to use. Let's check it using Filezilla. If you're new to Filezilla, please check the how to use Filezilla here.

  1. Open Filezilla and connect to the server as 'user1'.

  2. Upload a file to the server.

  3. Now connect to the remote server as 'user2' and you will see the same file has also been uploaded to this account's home folder.

  4. Now please proceed to Tutorial 2 - Error handling.