Auto deployment to FTP server with Travis-CI

Instead of integrating your app with deployment platforms like deployHQ, you can use Travis-CI to create your custom deployment process.

In my case, I just need to deploy my front-end static assets up to an FTP server.

Create your deploy script

I use node-ftp to do the ftp task. It is quite a easy-to-use module, the code is much like below:

Notice the environment variables I use to setup the FTP client. You should not hard code this info into the script; it is not secure and not flexible either. We can pass down all the variables from Travis-CI later on.

Config your travis.yml

Travis provides script deployment for you to create custom deployment process.

You just need to specify your deploy script and which branch you want to deploy. In my case, i want to exclude the /build dir from my repo, and I want the building process on the cloud instead of manually building the assets. So the whole config will be:

Config your environment variables

Open you project in Travis, and go to project settings:

And add all the variables you need to get access in your script:

Push your code and deploy!

Now push some code to your master (bad habit, though, you should use pull request instead) and see if it works.


  1. Hi can you provide and exemple on how to fullfill var uploadList with current directory and subdirectories please ? Thx

    1. Hi Stéphane, since the script is NodeJS, you can just use the variable __dirname to get the pathname of the directory of the current file, then you can calculate the “current directory” based on your project structure by path.resolve(__dirname', './xxxx')

  2. Hi Neekey,
    thank you for this great article. I have configured auto deploy for one site based on it.

    Here is example of my function to create uploadList

    const listFiles = dir => {
    let filesList = [];

    const files = fs.readdirSync(dir); => {
    const fullPath = path.resolve(dir, file);
    const stats = fs.lstatSync(fullPath);
    if (stats.isDirectory()) {
    filesList = filesList.concat(listFiles(fullPath));
    } else {
    if (dir.endsWith(BUILD_PATH)) {
    'local': fullPath,
    'target': file
    } else {
    const lastSeparator = dir.lastIndexOf(path.sep);
    const parentDir = dir.substring(lastSeparator);
    const targetPath =
    ${parentDir}${path.sep}${file}.replace(/\\/g, '/');

    'local': fullPath,
    'target': targetPath

    return filesList;

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.