Bitbucket Runner - sftp-deploy
Asked by Renato Baudouin:

sftp-deploy:0.5.7

Hello Comunity, I am trying to deploy to on-premise via Runner using the sftp-deploy. In the figure 1 you can find the *deployment yaml* . The figure 2 shows the *deployment logs* . It seems to be running ok beacuse it donwloads the "sftp-deploy:0.5.7" image, stablish the connection with the remote host but it its not enable to stablish the sftp connection beacuse of the *host key verification*.

At this point, I am not pretty sure how to pass to the image the known_hosts. I tried to use the SSH_KEY configuration, but it seems that it does not fecht the *Fingerprints* via *runners*.

Does any of you have an idea to work this out?  
Figure 1 - Deployment yaml  
![Deploy pipe.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/162036i870DC7CFD5E22BD9/image-size/large?v=v2&px=999 "Deploy pipe.PNG")

Figure 2 - Deployment logs

![Log.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/162037i64080B5C564D0465/image-size/large?v=v2&px=999 "Log.PNG")


Answers:
author: Renato Baudouin
body: At the end I decided to stop using the image: "atlassian/sftp-deploy:0.5.7" and copy the artifact using sshpass using the image: "atlassian/default-image:latest". Here is the final pipeline:

![Deployment with sshpass.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/166633i81453BCA4B2E3C6D/image-size/large?v=v2&px=999 "Deployment with sshpass.PNG")

comments: author: hitesh-makwana
body: Hi Renato,

Thank you so much. I was having sftp issue for fresh deployment with  
atlassian/sftp-deploy:0.5.8. I searched a lot and tried everything but didn't work. Able to deploy files but not folder which doesn't already exist on server. Finally able to do that with ssh.


author: Renato Baudouin
body: You are welcome :). Glad it helps you.


author: Viktoras Domarkas
body: Hi Renato,

If you still have problems you can use the tutorial I followed when creating the pipeline: <https://www.youtube.com/watch?v=OCA_jB1Dw0I>

The part that you need starts at 13:23

comments: author: Timothy Gonzalez
body: Excellent video. To provide the answer on this post the solution was to go to Repository Settings -\> SSH Keys then under known hosts enter the domain/ip of the server you are trying to connect to, get the finger print, then add the host.


author: Caroline R
body: Hi, [@Renato Baudouin](/t5/user/viewprofilepage/user-id/4288202)!

Thank you for reaching out to Atlassian Community!

In order to further investigate this issue, could you please confirm:

1. What is the Runner version you are using? You can find it in the Runner log on the top.

2. Have you fetched the host fingerprints in the Pipeline?

Thank you.

Kind regards,  
Caroline

comments: author: Renato Baudouin
body: Hi Caroline,

Thank you for your response.

Here are my comments:

1. What is the Runner version you are using? It is Runner version: 1.174, Runner runtime: linux-docker

2. Have you fetched the host fingerprints in the Pipeline? I am not sure how to do it. I tried to user the SSH_KEY in the *repository settings*, but it seems that it does not fecht the *Fingerprints* via *runners* .


author: Caroline R
body: Hi, Renato.

Thanks for the information. It seems your Runner is not updated, so first of all, you need to upgrade the Runner version that has some bug fixes and some enhancements.

You can check in the following link how to update the runner:

* <https://support.atlassian.com/bitbucket-cloud/docs/troubleshooting-runners/#Updating-a-runner-version>

Also, by your last comment, I couldn't understand if you have fetched the host fingerprints in the Pipelines setting. So, in case you haven't, please follow the next steps to accomplish that:

* Open your repository in Bitbucket

* Click on Repository settings

* Under the Pipelines section, open **SSH keys**

* There, you can add the **known hosts** and **fetch the fingerprints**

Please, feel free to share any additional questions or concerns regarding this case.

Kind regards,  
Caroline


author: Renato Baudouin
body: Hi Caroline,

Thank you very much for your response. Yes, I tried to configure the **known hosts** the in the **SSH key**. But it is no able to fetch it, because my Remote Host is onPremise. Please check the Figure 3. So here is my questions:

* Is there a way to indicate that the fetch should be made through the runner?

Figure 3 - Diagram

![Diagrama.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/163342iA8CE421F157462BC/image-dimensions/544x315?v=v2 "Diagrama.PNG")


author: Caroline R
body: Hi, Renato!

Thank you for the additional information! In this case, you can add it in the Pipeline YML:

```
ssh-keyscan -p 20 -t rsa <Host URL> >> /.ssh/known_hosts
```

It should add the fingerprint. Please let me know how it goes and don't hesitate to ask for any further information if needed.

Kind regards,  
Caroline


author: Renato Baudouin
body: Hi Caroline,

I put the ssh-keyscan statement in the script section as shown in the Figure 1. But it seems that I still have a failed deployment.

Figuere 1 - YML

![Deploy pipeline 2.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/163823iC87062FFB9FE2FC0/image-size/large?v=v2&px=999 "Deploy pipeline 2.PNG")

Figure 2 - Log Error

![Log 2.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/163824i6095C7DE67393E88/image-size/large?v=v2&px=999 "Log 2.PNG")


author: Caroline R
body: Hi, Renato!

Thanks for sharing the logs. I see that there is a code 6 there, which means "File does not exist". You have specified LOCAL_PATH, however, I don't see any steps about the file generation.

In this case, could you please verify the file mentioned in the LOCAL_PATH variable? You can run the following command before the pipe to confirm if the directory exists and if there is something in it:

```
ls -lah 
```

Thank you.

Kind regards,  
Caroline


author: Renato Baudouin
body: Hi Caroline, you where rigth. I didn't check the correct path for the artifact. I verified that it downloads the artifact to this path: "/opt/atlassian/pipelines/agent/". I correct it but neithet i could make it work. At the end I decided to stop using the image: "atlassian/sftp-deploy:0.5.7" and copy the artifact using sshpass.


author: Renato Baudouin
body: By the way thank you very much for your assistance :)


Tags: bitbucket-cloud

bitbucket-pipelines

bitbucket-runners

cloud

sftp