SFTP upload config.yml not working

I am trying to run 2 tasks inside my config.yml the “installation” step works but when it continues to the second i get the following error:

mkdir `Blaat/wp-content/themes/blaat-theme' [Connecting...]
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 29]
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 28]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 27]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 26]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 25]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 24]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 23]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 22]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 21]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 20]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 19]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 18]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 17]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 16]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 15]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 14]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 13]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 12]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 11]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 10]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 9]   
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 8]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 7]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 6]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 5]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 4]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 3]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 2]  
cd `Blaat/wp-content/themes/blaat-theme' [Delaying before reconnect: 1]  
cd `Blaat/wp-content/themes/blaat-theme' []                              
mirror: Fatal error: Host key verification failed.

1 error detected
Exited with code 1

my config.yml:

version: 2.0

jobs:
  "install":
    docker:
      - image: circleci/node:10.16
    working_directory: ~/nm-workflows
    steps:
      - checkout
      - run:
          name: Install packages
          command: yarn install
      - run:
          name: Build packages
          command: yarn test-build

  "upload":
    docker:
      - image: circleci/node:10.16
    working_directory: ~/nm-workflows
    steps:
      - run:
          name: Install LFTP
          command: |
            sudo apt-get update;
            sudo apt-get install lftp;
      - checkout
      - run:
          name: uploading files using SFTP
          command: lftp sftp://${username}:${password}@${hostname} -e "mirror -v -R --exclude src/ --exclude webpack/ --exclude .babelrc --exclude .browserslistrc --exclude .eslintrc --exclude .gitignore --exclude .prettierrc --exclude .stylelintignore --exclude .stylelintrc --exclude bitbucket-pipelines.yml --exclude env.json --exclude yarn.lock  --exclude .git/ --exclude .circleci/ ./ ${site_name}/wp-content/themes/${theme}; quit"

workflows:
  version: 2
  build:
    jobs:
      - "install"
      - "upload"

How can i upload files using SFTP? What am i doing wrong?

I’d recommend using SSH keys rather than passwords. I can’t remember if you need to use SFTP or FTPS, but I’d suggest playing around with a key-based deploy on your local machine, and then replicate it on CircleCI once you have it working.

(The error of “Host key verification failed” suggests to me that you could do with installing a known_hosts file, either by generating it manually, or by running an SSH command to generate it).

I have created a SSH key from the project settings SSH permissions:

It says Installed key 9e:30:54:a6:0c:9a:3a:54:xx:xx:xx:xx:fd:ff:55:d4

and still fails on the SFTP setup…

mirror: Fatal error: Host key verification failed.

My new config:

version: 2
jobs:

  build:
    docker:
      - image: circleci/node:10.16
    branches:
          only:
            - develop
    working_directory:  ~/repo
    steps:
      - add_ssh_keys:
          fingerprints:
            - "9e:30:54:a6:0c:9a:3a:54:xx:xx:xx:xx:fd:ff:55:d4"

      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: yarn install

      - save_cache: # special step to save the dependency cache
            key: dependency-cache-{{ checksum "package.json" }}
            paths:
              - ./node_modules

      # run tests!
      - run: yarn test-build

      - run:
          name: Install LFTP
          command: |
            sudo apt-get update;
            sudo apt-get install lftp;
      - checkout
      - run:
          name: Send Via SFTP
          command: lftp sftp://${username}:${password}@${hostname} -e "mirror -v -R --exclude src/ --exclude webpack/ --exclude .babelrc --exclude .browserslistrc --exclude .eslintrc --exclude .gitignore --exclude .prettierrc --exclude .stylelintignore --exclude .stylelintrc --exclude bitbucket-pipelines.yml --exclude env.json --exclude yarn.lock  --exclude .git/ --exclude package.json --exclude .circleci/ ./ ${site_name}/wp-content/themes/${theme}; quit"

This is really killing my brains… 150 builds and still no luck always fails on SFTP upload :frowning: