transfer.sh icon indicating copy to clipboard operation
transfer.sh copied to clipboard

I created a template to transfer folders to zip archives

Open RemyyB opened this issue 4 years ago • 0 comments

Hi there,

Maybe you could add these to the examples, I added the ability to directly convert a folder to a zip archive and upload it (in Batch + Bash), maybe they can be used in the examples ;)

transfer() {
  TMPFOLDER="$(mktemp)"
  if [[ -d $1 ]]; then
    zip -qr $TMPFOLDER\$1.zip $1;
    curl --progress-bar --upload-file "$TMPFOLDER\$1.zip" https://transfer.sh/$(basename "$1.zip") | tee /dev/null;
    echo '';
  elif [[ -f $1 ]]; then
    curl --progress-bar --upload-file "$1" https://transfer.sh/$(basename "$1") | tee /dev/null;
    echo '';
  else
    echo "$1 is not valid"
    exit 1
  fi
}

alias transfer=transfer
@echo off
setlocal ENABLEEXTENSIONS
set FN=%~nx1
set FULL=%1
set ATTR=%~a1
set DIRATTR=%ATTR:~0,1%

if /I "%DIRATTR%"=="d" (
  SET filebase = Join-Path $PSScriptRoot %1
  powershell Compress-Archive -Update -Path "$(Join-Path (Resolve-Path .\).Path %1)" -DestinationPath "$(Join-Path (Resolve-Path $Env:TEMP).Path %1)"
  powershell -noprofile -command Write-Output "$(Invoke-Webrequest -Method put -Infile $(Join-Path (Resolve-Path $Env:TEMP).Path %1.zip) https://transfer.sh/%1.zip).Content"
) else (
  powershell -noprofile -command Write-Output "$(Invoke-Webrequest -Method put -Infile $Env:FULL https://transfer.sh/$Env:FN).Content"
)

Edit: I see that I have a bug if the folder or file has a space in it, will fix it first :)

Remy

RemyyB avatar Apr 13 '20 19:04 RemyyB