| 1 | + | # crash.directory |
| 2 | + | |
| 3 | + | Easy and fast file sharing from the command-line. |
| 4 | + | |
| 5 | + | ## Warning |
| 6 | + | |
| 7 | + | Downloads on [crash.directory](https://crash.directory) are public and unrestricted but, in order to prevent abuses, the file uploads are protected by the HTTPS basic auth header. |
| 8 | + | Replace “user:pass” in the examples below with your provided credentials, you can try to ask for them on [crash.contact](https://crash.contact) |
| 9 | + | |
| 10 | + | Alternatively, for unauthenticated uploads, if you don't mind NOT using crash.directory, you can go with the official public instance of the underlying sofware: transfer.sh |
| 11 | + | |
| 12 | + | ## Usage |
| 13 | + | |
| 14 | + | ### Upload: |
| 15 | + | ```bash |
| 16 | + | $ curl --upload-file ./hello.txt https://user:[email protected]/hello.txt |
| 17 | + | ``` |
| 18 | + | |
| 19 | + | ### Encrypt & Upload: |
| 20 | + | ```bash |
| 21 | + | $ cat /tmp/hello.txt|gpg -ac -o-|curl -X PUT --upload-file "-" https://user:[email protected]/test.txt |
| 22 | + | ```` |
| 23 | + | |
| 24 | + | ### Download & Decrypt: |
| 25 | + | ```bash |
| 26 | + | $ curl https://crash.directory/1lDau/test.txt|gpg -o- > /tmp/hello.txt |
| 27 | + | ``` |
| 28 | + | |
| 29 | + | ### Upload to Virustotal: |
| 30 | + | ```bash |
| 31 | + | $ curl -X PUT --upload-file nhgbhhj https://user:[email protected]/test.txt/virustotal |
| 32 | + | ``` |
| 33 | + | |
| 34 | + | ### Deleting |
| 35 | + | ```bash |
| 36 | + | $ curl -X DELETE <X-Url-Delete Response Header URL> |
| 37 | + | ``` |
| 38 | + | |
| 39 | + | ## Request Headers |
| 40 | + | |
| 41 | + | ### Max-Downloads |
| 42 | + | ```bash |
| 43 | + | $ curl --upload-file ./hello.txt https://user:[email protected]/hello.txt -H "Max-Downloads: 1" # Limit the number of downloads |
| 44 | + | ``` |
| 45 | + | |
| 46 | + | ### Max-Days |
| 47 | + | ```bash |
| 48 | + | $ curl --upload-file ./hello.txt https://user:[email protected]/hello.txt -H "Max-Days: 1" # Set the number of days before deletion |
| 49 | + | ``` |
| 50 | + | |
| 51 | + | ## Response Headers |
| 52 | + | |
| 53 | + | ### X-Url-Delete |
| 54 | + | |
| 55 | + | The URL used to request the deletion of a file and returned as a response header. |
| 56 | + | ```bash |
| 57 | + | curl -sD - --upload-file ./hello https://user:[email protected]/hello.txt | grep -i 'X-Url-Delete' |
| 58 | + | X-Url-Delete: https://crash.directory/hello.txt/BAYh0/hello.txt/PDw0NHPcqU |
| 59 | + | ``` |
| 60 | + | |
| 61 | + | ## Examples |
| 62 | + | |
| 63 | + | See good usage examples on [examples.md](examples.md) |
| 64 | + | |
| 65 | + | ## Link aliases |
| 66 | + | |
| 67 | + | Create direct download link: |
| 68 | + | |
| 69 | + | https://crash.directory/1lDau/test.txt --> https://crash.directory/get/1lDau/test.txt |
| 70 | + | |
| 71 | + | Inline file: |
| 72 | + | |
| 73 | + | https://crash.directory/1lDau/test.txt --> https://crash.directory/inline/1lDau/test.txt |
| 74 | + | |
| 75 | + | |
| 76 | + | ## Shell functions |
| 77 | + | |
| 78 | + | ### Bash and zsh (multiple files uploaded as zip archive) |
| 79 | + | ##### Add this to .bashrc or .zshrc or its equivalent |
| 80 | + | ```bash |
| 81 | + | transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://user:[email protected]/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://user:[email protected]/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://user:[email protected]/$file_name"|tee /dev/null;fi;} |
| 82 | + | ``` |
| 83 | + | |
| 84 | + | #### Now you can use transfer function |
| 85 | + | ``` |
| 86 | + | $ transfer hello.txt |
| 87 | + | ``` |
| 88 | + | |
| 89 | + | |
| 90 | + | ### Bash and zsh (with delete url, delete token output and prompt before uploading) |
| 91 | + | ##### Add this to .bashrc or .zshrc or its equivalent |
| 92 | + | |
| 93 | + | <details><summary>Expand</summary><p> |
| 94 | + | |
| 95 | + | ```bash |
| 96 | + | transfer() |
| 97 | + | { |
| 98 | + | local file |
| 99 | + | declare -a file_array |
| 100 | + | file_array=("${@}") |
| 101 | + | |
| 102 | + | if [[ "${file_array[@]}" == "" || "${1}" == "--help" || "${1}" == "-h" ]] |
| 103 | + | then |
| 104 | + | echo "${0} - Upload arbitrary files to \"crash.directory\"." |
| 105 | + | echo "" |
| 106 | + | echo "Usage: ${0} [options] [<file>]..." |
| 107 | + | echo "" |
| 108 | + | echo "OPTIONS:" |
| 109 | + | echo " -h, --help" |
| 110 | + | echo " show this message" |
| 111 | + | echo "" |
| 112 | + | echo "EXAMPLES:" |
| 113 | + | echo " Upload a single file from the current working directory:" |
| 114 | + | echo " ${0} \"image.img\"" |
| 115 | + | echo "" |
| 116 | + | echo " Upload multiple files from the current working directory:" |
| 117 | + | echo " ${0} \"image.img\" \"image2.img\"" |
| 118 | + | echo "" |
| 119 | + | echo " Upload a file from a different directory:" |
| 120 | + | echo " ${0} \"/tmp/some_file\"" |
| 121 | + | echo "" |
| 122 | + | echo " Upload all files from the current working directory. Be aware of the webserver's rate limiting!:" |
| 123 | + | echo " ${0} *" |
| 124 | + | echo "" |
| 125 | + | echo " Upload a single file from the current working directory and filter out the delete token and download link:" |
| 126 | + | echo " ${0} \"image.img\" | awk --field-separator=\": \" '/Delete token:/ { print \$2 } /Download link:/ { print \$2 }'" |
| 127 | + | echo "" |
| 128 | + | echo " Show help text from \"crash.directory\":" |
| 129 | + | echo " curl --request GET \"https://crash.directory\"" |
| 130 | + | return 0 |
| 131 | + | else |
| 132 | + | for file in "${file_array[@]}" |
| 133 | + | do |
| 134 | + | if [[ ! -f "${file}" ]] |
| 135 | + | then |
| 136 | + | echo -e "\e[01;31m'${file}' could not be found or is not a file.\e[0m" >&2 |
| 137 | + | return 1 |
| 138 | + | fi |
| 139 | + | done |
| 140 | + | unset file |
| 141 | + | fi |
| 142 | + | |
| 143 | + | local upload_files |
| 144 | + | local curl_output |
| 145 | + | local awk_output |
| 146 | + | local filename |
| 147 | + | |
| 148 | + | du --total --block-size="K" --dereference "${file_array[@]}" >&2 |
| 149 | + | # be compatible with "bash" |
| 150 | + | if [[ "${ZSH_NAME}" == "zsh" ]] |
| 151 | + | then |
| 152 | + | read $'upload_files?\e[01;31mDo you really want to upload the above files ('"${#file_array[@]}"$') to "crash.directory"? (Y/n): \e[0m' |
| 153 | + | elif [[ "${BASH}" == *"bash"* ]] |
| 154 | + | then |
| 155 | + | read -p $'\e[01;31mDo you really want to upload the above files ('"${#file_array[@]}"$') to "crash.directory"? (Y/n): \e[0m' upload_files |
| 156 | + | fi |
| 157 | + | |
| 158 | + | case "${upload_files:-y}" in |
| 159 | + | "y"|"Y") |
| 160 | + | # for the sake of the progress bar, execute "curl" for each file. |
| 161 | + | # the parameters "--include" and "--form" will suppress the progress bar. |
| 162 | + | for file in "${file_array[@]}" |
| 163 | + | do |
| 164 | + | filename="${file##*/}" |
| 165 | + | # show delete link and filter out the delete token from the response header after upload. |
| 166 | + | # it is important to save "curl's" "stdout" via a subshell to a variable or redirect it to another command, |
| 167 | + | # which just redirects to "stdout" in order to have a sane output afterwards. |
| 168 | + | # the progress bar is redirected to "stderr" and is only displayed, |
| 169 | + | # if "stdout" is redirected to something; e.g. ">/dev/null", "tee /dev/null" or "| <some_command>". |
| 170 | + | # the response header is redirected to "stdout", so redirecting "stdout" to "/dev/null" does not make any sense. |
| 171 | + | # redirecting "curl's" "stderr" to "stdout" ("2>&1") will suppress the progress bar. |
| 172 | + | curl_output=$(curl --request PUT --progress-bar --dump-header - --upload-file "${file}" "https://user:[email protected]/${filename}") |
| 173 | + | awk_output=$(awk \ |
| 174 | + | 'gsub("\r", "", $0) && tolower($1) ~ /x-url-delete/ \ |
| 175 | + | { |
| 176 | + | delete_link=$2; |
| 177 | + | print "Delete command: curl --request DELETE " "\""delete_link"\""; |
| 178 | + | |
| 179 | + | gsub(".*/", "", delete_link); |
| 180 | + | delete_token=delete_link; |
| 181 | + | print "Delete token: " delete_token; |
| 182 | + | } |
| 183 | + | |
| 184 | + | END{ |
| 185 | + | print "Download link: " $0; |
| 186 | + | }' <<< "${curl_output}") |
| 187 | + | |
| 188 | + | # return the results via "stdout", "awk" does not do this for some reason. |
| 189 | + | echo -e "${awk_output}\n" |
| 190 | + | |
| 191 | + | # avoid rate limiting as much as possible; nginx: too many requests. |
| 192 | + | if (( ${#file_array[@]} > 4 )) |
| 193 | + | then |
| 194 | + | sleep 5 |
| 195 | + | fi |
| 196 | + | done |
| 197 | + | ;; |
| 198 | + | |
| 199 | + | "n"|"N") |
| 200 | + | return 1 |
| 201 | + | ;; |
| 202 | + | |
| 203 | + | *) |
| 204 | + | echo -e "\e[01;31mWrong input: '${upload_files}'.\e[0m" >&2 |
| 205 | + | return 1 |
| 206 | + | esac |
| 207 | + | } |
| 208 | + | ``` |
| 209 | + | |
| 210 | + | </p></details> |
| 211 | + | |
| 212 | + | #### Sample output |
| 213 | + | ```bash |
| 214 | + | $ ls -lh |
| 215 | + | total 20M |
| 216 | + | -rw-r--r-- 1 <some_username> <some_username> 10M Apr 4 21:08 image.img |
| 217 | + | -rw-r--r-- 1 <some_username> <some_username> 10M Apr 4 21:08 image2.img |
| 218 | + | $ transfer image* |
| 219 | + | 10240K image2.img |
| 220 | + | 10240K image.img |
| 221 | + | 20480K total |
| 222 | + | Do you really want to upload the above files (2) to "crash.directory"? (Y/n): |
| 223 | + | ######################################################################################################################################################################################################################################## 100.0% |
| 224 | + | Delete command: curl --request DELETE "https://crash.directory/wJw9pz/image2.img/mSctGx7pYCId" |
| 225 | + | Delete token: mSctGx7pYCId |
| 226 | + | Download link: https://crash.directory/wJw9pz/image2.img |
| 227 | + | |
| 228 | + | ######################################################################################################################################################################################################################################## 100.0% |
| 229 | + | Delete command: curl --request DELETE "https://crash.directory/ljJc5I/image.img/nw7qaoiKUwCU" |
| 230 | + | Delete token: nw7qaoiKUwCU |
| 231 | + | Download link: https://crash.directory/ljJc5I/image.img |
| 232 | + | |
| 233 | + | $ transfer "image.img" | awk --field-separator=": " '/Delete token:/ { print $2 } /Download link:/ { print $2 }' |
| 234 | + | 10240K image.img |
| 235 | + | 10240K total |
| 236 | + | Do you really want to upload the above files (1) to "crash.directory"? (Y/n): |
| 237 | + | ######################################################################################################################################################################################################################################## 100.0% |
| 238 | + | tauN5dE3fWJe |
| 239 | + | https://crash.directory/MYkuqn/image.img |
| 240 | + | ``` |
| 241 | + | |
| 242 | + | ## Creators |
| 243 | + | |
| 244 | + | **Remco Verhoef** |
| 245 | + | - <https://twitter.com/remco_verhoef> |
| 246 | + | - <https://twitter.com/dutchcoders> |
| 247 | + | |
| 248 | + | **Uvis Grinfelds** |
| 249 | + | |
| 250 | + | ## Maintainer |
| 251 | + | |
| 252 | + | **Andrea Spacca** |
| 253 | + | |
| 254 | + | **Stefan Benten** |
| 255 | + | |
| 256 | + | ## Copyright and License |
| 257 | + | |
| 258 | + | Code and documentation copyright 2011-2018 Remco Verhoef. |
| 259 | + | Code and documentation copyright 2018-2020 Andrea Spacca. |
| 260 | + | Code and documentation copyright 2020- Andrea Spacca and Stefan Benten. |
| 261 | + | |
| 262 | + | Code released under [the MIT license](LICENSE). |
| 263 | + | |