.bashrc transfer command code fails on HTTPS servers #136

Closed
opened 2026-01-19 18:29:07 +00:00 by michael · 4 comments
Owner

Originally created by @yelodevopsi on GitHub.

The bug lies somewhere in the generated transfer() alias code under # Add this to .bashrc or .zshrc or its equivalent

I've tested some examples, but I'm not that fluent in shell-script so I'll just post the results of the test. Maybe someone can pinpoint where this is going wrong:

The alias generated is this:

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://my.domain.com/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://my.domain.com/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://my.domain.com/$file_name"|tee /dev/null;fi;}

I've re-added and tested the code multiple time and refreshed with source ~/.bashrc

PS: I've replaced my real domain with my.domain.com and IP's with 123.123.123.123 below

Now - It works using these commands however:

  • transfer hello.txt For some wierd reason it always works with .txt files?
  • curl --progress-bar --upload-file compressed.zip https://my.domain.com/compressed.zip
  • curl --progress-bar --upload-file dave.jpg https://my.domain.com/dave.jpg => https://my.domain.com/wekBPA/dave.jpg

Fails with almost anything except hello.txt or pure text-files:

  • transfer compressed.zip
  • transfer dave.jpg

They give the errors in client and server respectively:

client:

transfer dave.jpg
######################################################################## 100.0%
open /tmp/transfer-984508353: no such file or directory

docker-server:

[transfer.sh]2021/12/10 22:11:38 123.123.123.123:26890 - - [2021-12-10T22:11:38Z] "PUT /dave.jpg HTTP/2.0" 500  "" "curl/7.58.0"

The server-docker code:

docker run --publish 8080:8080 --publish 443:443 --volume /etc/letsencrypt:/etc/letsencrypt dutchcoders/transfer.sh:latest --provider local --basedir / --tls-cert-file /etc/letsencrypt/live/my.domain.com/fullchain.pem --tls-private-key /etc/letsencrypt/live/my.domain.com/privkey.pem --tls-listener :443 --tls-listener-only

From the error-msg I assumed it had something to do with my --basedir / param, but --basedir /tmp/gives the same error. Beside the equivalent curl-commands above should also fail right?

The client I'm testing from has this curl version:

curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24

And server:
Ubuntu 18.04.5 LTS

Originally created by @yelodevopsi on GitHub. The bug lies somewhere in the generated transfer() alias code under `# Add this to .bashrc or .zshrc or its equivalent` I've tested some examples, but I'm not that fluent in shell-script so I'll just post the results of the test. Maybe someone can pinpoint where this is going wrong: The alias generated is this: ``` 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://my.domain.com/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://my.domain.com/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://my.domain.com/$file_name"|tee /dev/null;fi;} ``` I've re-added and tested the code multiple time and refreshed with `source ~/.bashrc` PS: I've replaced my real domain with `my.domain.com` and IP's with `123.123.123.123` below Now - It works using these commands however: * `transfer hello.txt` For some wierd reason it always works with .txt files? * `curl --progress-bar --upload-file compressed.zip https://my.domain.com/compressed.zip` * `curl --progress-bar --upload-file dave.jpg https://my.domain.com/dave.jpg` => `https://my.domain.com/wekBPA/dave.jpg` Fails with almost anything except `hello.txt` or pure text-files: * `transfer compressed.zip` * `transfer dave.jpg` They give the errors in client and server respectively: client: ``` transfer dave.jpg ######################################################################## 100.0% open /tmp/transfer-984508353: no such file or directory ``` docker-server: ```[transfer.sh]2021/12/10 22:11:38 open /tmp/transfer-984508353: no such file or directory [transfer.sh]2021/12/10 22:11:38 123.123.123.123:26890 - - [2021-12-10T22:11:38Z] "PUT /dave.jpg HTTP/2.0" 500 "" "curl/7.58.0" ``` The server-docker code: ``` docker run --publish 8080:8080 --publish 443:443 --volume /etc/letsencrypt:/etc/letsencrypt dutchcoders/transfer.sh:latest --provider local --basedir / --tls-cert-file /etc/letsencrypt/live/my.domain.com/fullchain.pem --tls-private-key /etc/letsencrypt/live/my.domain.com/privkey.pem --tls-listener :443 --tls-listener-only ``` From the error-msg I assumed it had something to do with my `--basedir /` param, but `--basedir /tmp/`gives the same error. Beside the equivalent curl-commands above should also fail right? The client I'm testing from has this curl version: ``` curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3 Release-Date: 2018-01-24 ``` And server: ```Ubuntu 18.04.5 LTS```
Author
Owner

@paolafrancesca commented on GitHub:

you can change the command to

curl -q --upload-file "$1" https://io.gule.cloud/$(basename "$1")

tee /dev/null is required to show the progress bar and print the output in seamless way

if you renounce the progress bar you can do without tee

you can also check man tee on the system where the command is failing, to see if it has different params and how to fix

@paolafrancesca commented on GitHub: you can change the command to ``` curl -q --upload-file "$1" https://io.gule.cloud/$(basename "$1") ``` `tee /dev/null` is required to show the progress bar and print the output in seamless way if you renounce the progress bar you can do without tee you can also check `man tee` on the system where the command is failing, to see if it has different params and how to fix
Author
Owner

@yelodevopsi commented on GitHub:

Also a minor "bug" with the .bashrc code is that there is not a line-break after the response from the server, which makes the terminal go:

myuser@my.domain.com:~$ transfer hello.txt
######################################################################## 100.0%
https://io.gule.cloud/O64WSg/hello.txtmyuser@my.domain.com:~$

can this be added too?

@yelodevopsi commented on GitHub: Also a minor "bug" with the .bashrc code is that there is not a line-break after the response from the server, which makes the terminal go: ``` myuser@my.domain.com:~$ transfer hello.txt ######################################################################## 100.0% https://io.gule.cloud/O64WSg/hello.txtmyuser@my.domain.com:~$ ``` can this be added too?
Author
Owner

@yelodevopsi commented on GitHub:

I just found the bug:
It seems I don't have access to
tee /dev/null;
on the buggy server

Is there a better way to write this maybe?

Btw: For the errors above, I think text-files are short enough to just not make the /tmp/-folder transfer not be utilized, thus making hello.txt work maybe?

@yelodevopsi commented on GitHub: I just found the bug: It seems I don't have access to ```tee /dev/null;``` on the buggy server Is there a better way to write this maybe? Btw: For the errors above, I think text-files are short enough to just not make the /tmp/-folder transfer not be utilized, thus making hello.txt work maybe?
Author
Owner

@yelodevopsi commented on GitHub:

An update: It might be related to the system I'm using.

  • I just copied a shorted code working on another server running Ubuntu LTS 18.04.1 LTS and curl 7.58.0
transfer() {
    curl --progress-bar --upload-file "$1" https://io.gule.cloud/$(basename "$1") | tee /dev/null;
    echo
}

alias transfer=transfer

Tested the same code on the buggy server and it fails with the same error as above.

######################################################################## 100.0%
open /tmp/transfer-754974315: no such file or directory
@yelodevopsi commented on GitHub: An update: It might be related to the system I'm using. * I just copied a shorted code working on another server running `Ubuntu LTS 18.04.1 LTS` and `curl 7.58.0` ``` transfer() { curl --progress-bar --upload-file "$1" https://io.gule.cloud/$(basename "$1") | tee /dev/null; echo } alias transfer=transfer ``` Tested the same code on the buggy server and it fails with the same error as above. ```myuser@my.domain.com:/tmp$ transfer dave.jpg ######################################################################## 100.0% open /tmp/transfer-754974315: no such file or directory ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dutchcoders/transfer.sh#136