Skip to content
Snippets Groups Projects
Select Git revision
  • a5dacb36a9124b7c4cf6ac653c6915570b855f89
  • main default protected
  • revert-646-main
  • dependabot/go_modules/golang.org/x/oauth2-0.27.0
  • dependabot/go_modules/golang.org/x/crypto-0.35.0
  • dependabot/go_modules/golang.org/x/net-0.38.0
  • check-ci-20241026
  • aspacca-patch-1
  • seed-rand
  • fix-basic-auth
  • fix-header-map-change-after-writeheader-call
  • issue-503
  • issue-487
  • gpg-encryption-support
  • lint-accept-range
  • bump-min-go-version-and-include-tip
  • accept-range
  • local-google-fonts
  • parallel-range-requests
  • issue-485
  • sb/storj-bump
  • v1.6.1
  • v1.6.0
  • v1.5.0
  • v1.4.0
  • v1.3.1
  • v1.3.0
  • v1.2.6
  • v1.2.4
  • v1.2.3
  • v1.2.2
  • v1.2.1
  • v1.2.0
  • v1.1.7
  • v1.1.6
  • v1.1.5
  • v1.1.4
  • v1.1.3
  • v1.1.2
  • v1.1.1
  • v1.1.0
41 results

examples.md

Blame
  • user avatar
    干志雄 authored and GitHub committed
    * Add uploading and copy download command
    0eec2758
    History

    Table of Contents

    Aliases

    Add alias to .bashrc or .zshrc

    Using curl

    transfer() {
        curl --progress-bar --upload-file "$1" https://transfer.sh/$(basename "$1") | tee /dev/null;
        echo
    }
    
    alias transfer=transfer

    Using wget

    transfer() {
        wget -t 1 -qO - --method=PUT --body-file="$1" --header="Content-Type: $(file -b --mime-type "$1")" https://transfer.sh/$(basename "$1");
        echo
    }
    
    alias transfer=transfer

    Add alias for fish-shell

    Using curl

    function transfer --description 'Upload a file to transfer.sh'
        if [ $argv[1] ]
            # write to output to tmpfile because of progress bar
            set -l tmpfile ( mktemp -t transferXXXXXX )
            curl --progress-bar --upload-file "$argv[1]" https://transfer.sh/(basename $argv[1]) >> $tmpfile
            cat $tmpfile
            command rm -f $tmpfile
        else
            echo 'usage: transfer FILE_TO_TRANSFER'
        end
    end
    
    funcsave transfer

    Using wget

    function transfer --description 'Upload a file to transfer.sh'
        if [ $argv[1] ]
            wget -t 1 -qO - --method=PUT --body-file="$argv[1]" --header="Content-Type: (file -b --mime-type $argv[1])" https://transfer.sh/(basename $argv[1])
        else
            echo 'usage: transfer FILE_TO_TRANSFER'
        end
    end
    
    funcsave transfer

    Now run it like this:

    $ transfer test.txt

    Add alias on Windows

    Put a file called transfer.cmd somewhere in your PATH with this inside it:

    @echo off
    setlocal
    :: use env vars to pass names to PS, to avoid escaping issues
    set FN=%~nx1
    set FULL=%1
    powershell -noprofile -command "$(Invoke-Webrequest -Method put -Infile $Env:FULL https://transfer.sh/$Env:FN).Content"

    Uploading and Downloading

    Uploading with wget

    $ wget --method PUT --body-file=/tmp/file.tar https://transfer.sh/file.tar -O - -nv 

    Uploading with PowerShell

    PS H:\> invoke-webrequest -method put -infile .\file.txt https://transfer.sh/file.txt 

    Upload using HTTPie

    $ http https://transfer.sh/ -vv < /tmp/test.log 

    Uploading a filtered text file

    $ grep 'pound' /var/log/syslog | curl --upload-file - https://transfer.sh/pound.log 

    Downloading with curl

    $ curl https://transfer.sh/1lDau/test.txt -o test.txt

    Downloading with wget

    $ wget https://transfer.sh/1lDau/test.txt

    Archiving and backups

    Backup, encrypt and transfer a MySQL dump

    $ mysqldump --all-databases | gzip | gpg -ac -o- | curl -X PUT --upload-file "-" https://transfer.sh/test.txt

    Archive and upload directory

    $ tar -czf - /var/log/journal | curl --upload-file - https://transfer.sh/journal.tar.gz

    Uploading multiple files at once

    $ curl -i -F filedata=@/tmp/hello.txt -F filedata=@/tmp/hello2.txt https://transfer.sh/

    Combining downloads as zip or tar.gz archive

    $ curl https://transfer.sh/(15HKz/hello.txt,15HKz/hello.txt).tar.gz
    $ curl https://transfer.sh/(15HKz/hello.txt,15HKz/hello.txt).zip 

    Transfer and send email with link (using an alias)

    $ transfer /tmp/hello.txt | mail -s "Hello World" user@yourmaildomain.com 

    Encrypting and decrypting

    Encrypting files with password using gpg

    $ cat /tmp/hello.txt | gpg -ac -o- | curl -X PUT --upload-file "-" https://transfer.sh/test.txt

    Downloading and decrypting

    $ curl https://transfer.sh/1lDau/test.txt | gpg -o- > /tmp/hello.txt 

    Import keys from keybase

    $ keybase track [them] # Encrypt for recipient(s)
    $ cat somebackupfile.tar.gz | keybase encrypt [them] | curl --upload-file '-' https://transfer.sh/test.txt # Decrypt
    $ curl https://transfer.sh/sqUFi/test.md | keybase decrypt

    Scanning for viruses

    Scan for malware or viruses using Clamav

    $ wget http://www.eicar.org/download/eicar.com
    $ curl -X PUT --upload-file ./eicar.com https://transfer.sh/eicar.com/scan

    Upload malware to VirusTotal, get a permalink in return

    $ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/virustotal 

    Uploading and copy download command

    Download commands can be automatically copied to the clipboard after files are uploaded using transfer.sh.

    It was designed for Linux or macOS.

    1. Install xclip or xsel for Linux, macOS skips this step

    Install later, add pbcopy and pbpaste to .bashrc or .zshrc or its equivalent.

    • If use xclip, paste the following lines:
    alias pbcopy='xclip -selection clipboard'
    alias pbpaste='xclip -selection clipboard -o'
    • If use xsel, paste the following lines:
    alias pbcopy='xsel --clipboard --input'
    alias pbpaste='xsel --clipboard --output'

    2. Add Uploading and copy download command shell function

    1. Open .bashrc or .zshrc or its equivalent.

    2. Add the following shell script:

      transfer() {
        curl --progress-bar --upload-file "$1" https://transfer.sh/$(basename "$1") | pbcopy;
        echo "1) Download link:"
        echo "$(pbpaste)"
      
        echo "\n2) Linux or macOS download command:"
        linux_macos_download_command="wget $(pbpaste)"
        echo $linux_macos_download_command
      
        echo "\n3) Windows download command:"
        windows_download_command="Invoke-WebRequest -Uri "$(pbpaste)" -OutFile $(basename $1)"
        echo $windows_download_command
      
        case $2 in
          l|m)  echo $linux_macos_download_command | pbcopy
          ;;
          w)  echo $windows_download_command | pbcopy
          ;;
        esac
      }

    3. Test

    The transfer command has two parameters:

    1. The first parameter is the path to upload the file.

    2. The second parameter indicates which system's download command is copied. optional:

      • This parameter is empty to copy the download link.

      • l or m copy the Linux or macOS command that downloaded the file.

      • w copy the Windows command that downloaded the file.

    For example, The command to download the file on Windows will be copied:

    $ transfer ~/temp/a.log w
    ######################################################################## 100.0%
    1) Download link:
    https://transfer.sh/y0qr2c/a.log
    
    2) Linux or macOS download command:
    wget https://transfer.sh/y0qr2c/a.log
    
    3) Windows download command:
    Invoke-WebRequest -Uri https://transfer.sh/y0qr2c/a.log -OutFile a.log