Deploy to SFTP server

If you are new to Buddy, check out our quickstart guides that will tell you how to build, test and deploy your type of application.

📚 Learn more about SFTP action features, integrations and alternatives.

Buddy turns deployments into a breeze, allowing you to automatically update your servers on every push to branch. You can also deploy manually on click, or recurrently on time intervals.

Pipeline examplePipeline example

Configure SFTP action

  1. Create a new project, select your Git provider and choose the repository with your project
  2. Add a new pipeline and configure the details: name, trigger mode, and branch from which you want to deploy
  3. Look up and click SFTP on the action list: SFTP action locationSFTP action location
  4. Configure action details:
    • select authentication mode and provide the details to your server SFTP action configurationSFTP action configuration
If you are using build actions in your pipeline, make sure to select the Filesystem as the source to deploy artifacts and processed files.
  1. When ready, click Add this action to finish configuration.
Click the Test button to verify connection details before saving the action.
Buddy's deployment is based on changesets. This means only changed files are deployed, which makes it lightning fast ⚡️. The first deployment is always performed from scratch, unless you set a revision on the server beforehand.

What you need to know

  • Select Repository as the Source to deploy only the files from your repository. If you use build actions, select Pipeline Filesystem as the Source to add artifacts, processed files & uploaded static files.
  • You can use environment variables to store authentication details to your servers.
  • You can use Ignore paths to exclude files for deployment in More Options.

In order to upload symlinks via SCP it’s enough to use the recursive mode by adding the -r parameter:

scp -r$

However, enabling the mode will also copy the content to which the symlink points. This is troublesome if we only want the symlinks to be copied, and it’s not possible to do it in a different way with SCP. Usually, this is solved by using rsync:

rsync -avz -e ssh /scr-dir user@host:/dst-dir$

Unfortunately, this method is very time consuming. Below you will find a description how to automate and speed it up with Buddy.

Solution 1: Local Script + Server Upload + Host Script

The first solution employs some simple scripts and a deployment action. First we need a script grab-links.sh that will list all symlinks in the folder. The script will search the folder in recursive mode and create a file create-links.sh with instructions that will reproduce the symlinks on the target server:

# !/bin/sh

echo "#!/bin/sh\n" > create-links.sh
for file in $(find . -type l); do
            link=$(readlink $file);
            echo "if [ ! -L $file ]; then ln -s $link $file; fi" >> create-links.sh;
done$$$$$$$

Now, we need to save the script to a grab-links.sh file and execute:

chmod +x grab-links.sh
./grab-links.sh$$

This will generate create-links.sh that you can upload and run on the target server to reproduce your symlinks:

chmod +x create-links.sh
./create-links.sh$$

Contents of grab-links.shContents of grab-links.sh

Automation

In Buddy you can create a pipeline that will automatically perform all these steps on every push to the repository:

  1. Upload the script grab-links.sh to the repository
  2. Add a new pipeline and set the trigger mode to On every push
  3. Add Build action and enter the commands that will run the script in the Buddy’s infrastructure:
    chmod +x grab-links.sh
    ./grab-links.sh$$
  1. Add SFTP action that will upload the repository files with the newly generated script create-links.sh
  2. Add SSH action and enter the commands that will execute the script on the targer server:
 chmod +x create-links.sh
 ./create-links.sh$$

Reproducing symlinks on the serverReproducing symlinks on the server

Solution 2: Git Clone

Git handles symlinks exactly the way one could expect: if you push a symlink to the repository and somebody else clones this repository, the symlink will be reproduced in their local repo. So, basically, all that you need to do is install Git on the production server and run

git clone$

Automation

With Buddy you can execute git clone automatically on every push the repository. A good practice is to add unit tests to make sure your code is free of errors before it’s pulled.

  1. Add a new pipeline and set the trigger mode to On every push
  2. Add PHP Unit action and define your tests. It comes with Composer preinstalled, too.
  3. Add SSH action that will execute git clone on the external repository.

Running tests and pulling the symlinks on the serverRunning tests and pulling the symlinks on the server

Summary

Using Buddy to upload symlinks is just one of the many use cases the software can be used. You can expand your workflow and configure Buddy for example to:

Make sure to follow our blog and check out our guides for more inspiration and use cases.

Last modified on April 26, 2022

Questions?

Not sure how to configure a pipeline for your process? Reach out on the live-chat or contact support

Get Started

Sign up for free and deploy your project in less than 10 minutes.