# Uploading multiple files using CURL

**URL:** <https://travis-ci.community/t/uploading-multiple-files-using-curl/10660>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** build-env, travis-build\
**Created:** [November 23, 2020, 4:49am UTC](https://travis-ci.community/t/uploading-multiple-files-using-curl/10660 "2020-11-23T04:49:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SolarUltima](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/solarultima/32/4019_2.png) [@SolarUltima](https://travis-ci.community/u/SolarUltima)\
**Post date:** [November 23, 2020, 4:49am UTC](https://travis-ci.community/t/uploading-multiple-files-using-curl/10660/1 "2020-11-23T04:49:33Z")

</div>

I ultimately want automate my deployment process, using crons and by uploading the built artifacts to my server, which automatically registers these uploads and moves them where they need to go, so I can move them easily and efficiently.

The shell script I write is below:

```auto
find $TRAVIS_BUILD_DIR/dist/*.tar -type f -exec curl --ftp-create-dirs -T {} -u user:pass ftp://server.com/uploads/{} \. | grep pass/fail;

```

The last `{}` (in the destination path, where I want the files to deploy to) causes issues. In Travis these files are usually in the path `/home/travis/build/owner/repo/dist` , so adding `{}` to the destination will create these directories as well. This is the problem.

Thank you.

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [November 23, 2020, 4:54am UTC](https://travis-ci.community/t/uploading-multiple-files-using-curl/10660/2 "2020-11-23T04:54:10Z")

</div>

Hey as usual @SolarUltima,

The only solution I see fit is using `xargs`. The way you would do this with `xargs` would in my own opinion would be a parameter substitution. So in theory, in this bash script I’m going to write below for my example, this may give you a better scope when using `cURL` and `CRON` jobs in your `.travis.yml` file, and to understand the mechanism of action:

```bash
your_id=${USER}-on-${HOSTNAME}
echo "$your_id"
#
echo "Old \$PATH = $PATH"
PATH=${PATH}:/opt/bin # Add /opt/bin to $PATH for duration of script.
echo "New \$PATH = $PATH"  

```

This would work, but I think for this luckily, there’s a simpler solution - `xargs` is the way to go. Try the following:

```bash
find . -type f | xargs -L 1 bash -c 'curl --ftp-create-dirs -T $1 -u user:pass ftp://server.com/uploads/${1##*/}' \;

```

There’s also no reason for `grep`.

-Montana  
(Travis CI Staff)

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [November 23, 2020, 10:47am UTC](https://travis-ci.community/t/uploading-multiple-files-using-curl/10660/3 "2020-11-23T10:47:52Z")

</div>

1. You can `cd`/`pushd` to the appropriate directory so that the paths are just files. E.g. in a subshell so that the current directory in the main shell is not affected:

2. To upload everything in the same `curl` invocation, [I constructed a comma-separated list in curly braces (which `-T` requires to upload multiple files) with a Perl script](https://travis-ci.community/t/failing-to-run-compiled-python-extension/7456/7). For your case, that would be:

* * *

Also note that `.tar`s are uncompressed. You should probably pass `-z`/`-j`/`-J` to `tar -c` and/or change the extension to prevent confusion if you already do.

---

<div class="post-metadata">

**Author:** ![SolarUltima](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/solarultima/32/4019_2.png) [@SolarUltima](https://travis-ci.community/u/SolarUltima)\
**Post date:** [November 24, 2020, 6:52am UTC](https://travis-ci.community/t/uploading-multiple-files-using-curl/10660/4 "2020-11-24T06:52:21Z")

</div>

Both methods worked! thank you both

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [November 24, 2020, 8:09am UTC](https://travis-ci.community/t/uploading-multiple-files-using-curl/10660/5 "2020-11-24T08:09:48Z")

</div>

Glad we could help.  
-Montana  
(Travis CI Staff)
