2 # Remco Verhoef <remco@dutchcoders.io>
3 # https://gist.github.com/nl5887/a511f172d3fb3cd0e42d
4 # Modified to use tar command instead of zip
9 if [[ $# -eq 0 ]]; then
11 Error: no arguments specified.
13 Usage: transfer [file/folder] [options]
17 transfer /tmp/test.md -ca
18 cat /tmp/test.md | transfer test.md
19 cat /tmp/test.md | transfer test.md -ca
22 -ca Encrypt file with symmetric cipher and create ASCII armored output
27 if (( ! $+commands[curl] )); then
28 echo "Error: curl is not installed"
32 local tmpfile tarfile item basename
34 # get temporarily filename, output is written to this file show progress can be showed
35 tmpfile=$(mktemp -t transferXXX)
37 # upload stdin or file
40 # crypt file with symmetric cipher and create ASCII armored output
42 if [[ "$2" = -ca ]]; then
44 if (( ! $+commands[gpg] )); then
45 echo "Error: gpg is not installed"
53 gpg -aco - | curl -X PUT --progress-bar -T - "https://transfer.sh/$item" >> $tmpfile
55 curl --progress-bar --upload-file - "https://transfer.sh/$item" >> $tmpfile
58 basename=$(basename "$item" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
60 if [[ ! -e $item ]]; then
61 echo "File $item doesn't exist."
65 if [[ -d $item ]]; then
66 # tar directory and transfer
67 tarfile=$(mktemp -t transferXXX.tar.gz)
68 cd $(dirname $item) || {
69 echo "Error: Could not change to directory $(dirname $item)"
73 tar -czf $tarfile $(basename $item)
75 gpg -cao - "$tarfile" | curl --progress-bar -T "-" "https://transfer.sh/$basename.tar.gz.gpg" >> $tmpfile
77 curl --progress-bar --upload-file "$tarfile" "https://transfer.sh/$basename.tar.gz" >> $tmpfile
83 gpg -cao - "$item" | curl --progress-bar -T "-" "https://transfer.sh/$basename.gpg" >> $tmpfile
85 curl --progress-bar --upload-file "$item" "https://transfer.sh/$basename" >> $tmpfile