0

I' using a ci/cd environment on circleci that runs on ubuntu. I'm trying to send a folder (eventually delete old files) to a FTP address. I've tried ftp and lftp but I think they use prompt to connect to the FTP. I would like to avoid bash scripts as it complicated to access cicleci environment variables from there (I guess). so do you know any command line that would look a bit like this

upload-to-ftp $COMPLETE_URL_WITH_USER_AND_PASSWORD -i $FOLDER_PATH -o $REMOTE_FOLDER_PATH

but if I decide to use bash script I would like to be able to enter input in and non exited program for the moment here is my bash script and ci pipeline

  - run:
      name: Deploy on FTP
      command: |
          chmod 755 ./.circleci/deploy-to-ftp.sh
          ./.circleci/deploy-to-ftp.sh "$FTP_HOST"

bash:

ftp_host=${FTP_HOST}
lftp
echo $FTP_HOST
echo $(mirror -R /www/ /dist/my-app/browser/)
exit 1
JSmith
  • 103

1 Answers1

2

One possible way is to use (file is located in your home directory):
.netrc where you enter structure:

machine <name of the host>
login <username>
password <password for above user>

Then you can exec command:

ftp <name of the host> <<EOF
cd <REMOTE DIR>
lcd <LOCAL DIR>
mput *
bye
EOF

Be aware if you have subdirectories in you <LOCAL DIR> they will not be uploaded, only the files. EOF identifier must be uniq and on the last line there should not be space, tab, etc before the identifier!

If you want to use lftp the command will be something like:

lftp ftp://user:password@hostname -c "lcd <LOCAL DIR>; cd <REMOTE DIR>; mput *; bye"

Bash script which use ftp can se something like:

ftp $1 <<EOF
cd $3
lcd $2
mput *
bye
EOF

You put in .netrc records for every host/user/password you will use.

And you should start the script on this way:

/path/to/script.sh $FTP_HOST /www/ /dist/my-app/browser/

where the variable $FTP_HOST should be only the hostname or IP of the host and should exist in .netrc file!

Romeo Ninov
  • 7,848