Search code examples
ansibleftpput

How PUT file into FTP with Ansible?


I have a local file and I need to upload into a remote FTP (not SFTP) server with login.

Please, how could I do that?

Thanks in advance!


Solution

  • Depending on your use case, infrastructure, capabilities of the remote FTP server, etc., there might be several options.

    If you like to use plain File Transfer Protocol (FTP) over TCP/21

    If the FTP server software has additionally HTTP server capabilities implemented

    • The module uri - Interacts with webservices with parameter method: PUT

      - name: Upload content
         local_action:
           module: uri
           url: "http://ftp.example.oom"
           method: PUT
           url_username: "{{ ansible_user }}"
           url_password: "{{ ansible_password }}"
           body: "{{ lookup('file', fileToTransfer) }}"
         register: result
      

      ... not sure if this would work, haven't tested such setup yet and there is still information missing

    Other Q&A

    Further Documentation