Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ $ transfer upload /path/to/file.log custom.log
$ transfer upload --file=/path/to/file.log --slug=custom.log
$ transfer upload --file /path/to/file.log --slug custom.log
$ transfer upload -f /path/to/file.log -s custom.log

$ # Custom lifetime:
$ transfer upload --max-days 1 /path/to/file.log
$ transfer upload --max-downloads 10 /path/to/file.log
```

__Download samples:__
Expand Down Expand Up @@ -96,7 +100,7 @@ Usage:
[--url|-u <url>]

transfer upload [<file> [slug]]
[--encrypt|-e] [--file|-f <file>] [--password|-p <password>] [--slug|-s <slug>]
[--encrypt|-e] [--max-days|-y <days>] [--max-downloads|-l <dls>] [--file|-f <file>] [--password|-p <password>] [--slug|-s <slug>]
[--trace|-x]

Commands:
Expand All @@ -108,6 +112,8 @@ More Information:
repo https://github.com/rockymadden/transfer-cli
```

To use a selfhosted instance of transfer.sh, change the `server` variable at the top of the script.

## License
```
The MIT License (MIT)
Expand Down
23 changes: 19 additions & 4 deletions src/transfer
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env bash

server="https://transfer.sh"

# COMMAND PARSING #################################################################################
cmd="${1}" ; shift
case "${1}" in
download|dl|d) cmd="download" ;;
upload|up|ul|u) cmd="upload" ;;
*) cmd="${1}" ;;
esac
shift

# STDIN FRIENDLINESS ##############################################################################
case "${cmd}" in
Expand All @@ -15,6 +22,10 @@ while (( "$#" )); do
--encrypt|-e) encrypt=0 ; shift ;;
--file=*) file=${1/--file=/''} ; shift ;;
--file*|-f*) file=${2} ; shift ; shift ;;
--max-days=*) max_days=${1/--max-days=/''} ; shift ;;
--max-days*|-y*) max_days=${2} ; shift ; shift ;;
--max-downloads=*) max_downloads=${1/--max-downloads=/''} ; shift ;;
--max-downloads*|-l*) max_downloads=${2} ; shift ; shift ;;
--password=*) password=${1/--password=/''} ; shift ;;
--password*|-p*) password=${2} ; shift ; shift ;;
--slug=*) slug=${1/--slug=/''} ; shift ;;
Expand Down Expand Up @@ -97,6 +108,10 @@ function upload() {
local tmpurl=$(mktemp -t transfer.url.XXXXXXXX)
trap "rm -f ${tmpurl}" 0

local headers=""
[ -n "${max_days}" ] && headers="${headers}-H \"Max-Days: ${max_days}\" "
[ -n "${max_downloads}" ] && headers="${headers}-H \"Max-Downloads: ${max_downloads}\""

if [ -n "${file}" ]; then
if [ -d ${file} ]; then
[ -z "${slug}" ] && slug="$(basename ${file} | sed -e 's/[^a-zA-Z0-9._-]/-/g').tar.gz"
Expand All @@ -108,18 +123,18 @@ function upload() {

cat "${tmptar}" |
([ -z "${encrypt}" ] && cat || openssl aes-256-cbc -a -salt ${password:+-k "${password}"}) |
curl --progress-bar --upload-file - "https://transfer.sh/${slug}" > ${tmpurl}
eval curl --progress-bar "${headers}" --upload-file - "${server}/${slug}" > ${tmpurl}
elif [ -f "${file}" ]; then
[ -z "${slug}" ] && slug="$(basename ${file} | sed -e 's/[^a-zA-Z0-9._-]/-/g')"

cat "${file}" |
([ -z "${encrypt}" ] && cat || openssl aes-256-cbc -a -salt ${password:+-k "${password}"}) |
curl --progress-bar --upload-file - "https://transfer.sh/${slug}" > ${tmpurl}
eval curl --progress-bar "${headers}" --upload-file - "${server}/${slug}" > ${tmpurl}
fi
elif [ -n "${stdin}" ]; then
echo "${stdin}" |
([ -z "${encrypt}" ] && cat || openssl aes-256-cbc -a -salt ${password:+-k "${password}"}) |
curl --progress-bar --upload-file - "https://transfer.sh/${slug}" > ${tmpurl}
eval curl --progress-bar "${headers}" --upload-file - "${server}/${slug}" > ${tmpurl}
fi

cat ${tmpurl}
Expand Down