Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URL encoding to transfer function to handle whitespaces #548

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ You need to create an OAuth Client id from console.cloud.google.com, download th
### Bash and zsh (multiple files uploaded as zip archive)
##### Add this to .bashrc or .zshrc or its equivalent
```bash
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://transfer.sh/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;}
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://transfer.sh/"|tee /dev/null;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;fi;}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;

here $file is a directory, we cd into it and zip recursively sending output to stdout, curl get from stdin the upload file from stdin.
we should change to zip to file and use it for curl

else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;fi

same here: it's not enough to remove $file_name, we should remove cat and curl getting the upload file from stdin:

else curl --progress-bar --upload-file "$file" "https://transfer.sh/"|tee /dev/null;fi
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_name=$(basename "$1");
        if [ ! -e "$1" ];then 
            echo "$1: No such file or directory">&2;
            return 1;
        fi;
        if [ -d   "$1" ];then 
            zip_file="$1.zip";
            pushd "$1";
            zip -r -q "$zip_file" . && curl --progress-bar --upload-file "$zip_file" "https://transfer.sh/"|tee /dev/null && rm "$zip_file";
            popd;
        else 
            curl --progress-bar --upload-file "$file" "https://transfer.sh/"|tee /dev/null;
        fi;
    else 
        curl --progress-bar --upload-file "$1" "https://transfer.sh/"|tee /dev/null;
    fi;
}

this should be the proper one: please @snowphone check if it works for you and feel free to push the change :)

thanks

```

#### Now you can use transfer function
Expand Down