Simple SFTP Deployment
Asked by Edison Chango:

Trying to execute a simple FTP deploy from bitbucket repo to FTP host

Pipelines YML at "<https://bitbucket.org/echango/modx_pb_pdf_upload/deployments>" keeps displaying error on lines by columns such as; "Expected a section but found sequence" or "Unexpected property 'deployment'" or "Unexpected property 'script'"

Kept on trying to execute code samples for FTP or SFTP deployments no luck using image provided by BITBUCKET

Even searched for thsi Post <https://bitbucket.org/ian_buchanan/ftp-example/src/master/> which seems to be outdated but always appears on search results:  
<https://confluence.atlassian.com/search/?queryString=FTP%20with%20bitbucket>


Answers:
author: Patrik S
body: Hello [@Edison Chango](/t5/user/viewprofilepage/user-id/1246553) ,

Thank you for reaching out to Atlassian Community!

The errors you reported are usually because of formatting issues in your YML file. You can use the below link to validate the YMLconfiguration for any error in the formatting before actually committing the bitbucket-pipelines.yml file in your repository :

* <https://bitbucket-pipelines.atlassian.io/validator>

As for the SFTP deploy, I would suggest using the [atlassian/sftp-deploy](https://bitbucket.org/product/features/pipelines/integrations?p=atlassian/sftp-deploy) pipe, as it has most of the underlying code already done for you, and you just need to provide some variables. Please find below an example of using that pipe :

```
pipelines:
  default:
    - step:
        name: 'Deploy with SFTP'
        script:
          - echo "This step will use atlassian/sftp-deploy pipe"
          - pipe: atlassian/sftp-deploy:0.5.11
            variables:
              USER: '<string>'
              SERVER: '<string>'
              REMOTE_PATH: '<string>'
              LOCAL_PATH: '<string>' #Optional
```

For more details about the atlassian/sftp-deploy pipe and how to configure the variables, please refer to the following documentation :

* <https://bitbucket.org/product/features/pipelines/integrations?p=atlassian/sftp-deploy>

Hope that helps! Let me know in case you have any questions or run into any issues.

Thank you [@Edison Chango](/t5/user/viewprofilepage/user-id/1246553) .

Kind regards,

Patrik S

comments: author: Edison Chango
body: This seems to be working. Just one more detail. Not sure f this is about the YM, but after all deployments were performed, there seems to be a lack of privileges or command to be run for getting files deleted. Even simple txt files, after they are deleted from Source tree, removed from bitbucket, they do not get deleted from server.

This YML should be showcased, how can i promote this code, it comes very handy and should be accessible to anybody deploying small stuff? Just need to get the successful deletion issue.

Any advise will be greatly appreciated.

Ed


author: Patrik S
body: Hello [@Edison Chango](/t5/user/viewprofilepage/user-id/1246553) ,

If I understand you correctly, you would like the files deleted from the source to also be deleted from the destination (your FTP server).

If that is the case, I'm afraid that SFTP does not support it, as it only allows you to transfer the files from one side to another, and not actually synch the folders.

In order to actually synch the files, and delete from the destination folder all the extraneous files that are not in the source folder, I would suggest using the **atlassian/rsync-deploy** pipe with the DELETE_FLAG :

```
- pipe: atlassian/rsync-deploy:0.7.1  variables:    USER: '<string>'    SERVER: '<string>'    REMOTE_PATH: '<string>'    LOCAL_PATH: '<string>'
    DELETE_FLAG: 'true'
```

This will delete all the files from the destination folder that are not in the source folder.

More details about the available variables for that pipe can be found in its official documentation :

* <https://bitbucket.org/product/features/pipelines/integrations?p=atlassian/rsync-deploy>

Thank you, [@Edison Chango](/t5/user/viewprofilepage/user-id/1246553) !

Kind regards,

Patrik S


Tags: bitbucket-cloud

bitbucket-pipelines

cloud