I created a template to transfer folders to zip archives #216

Open
opened 2026-01-19 18:29:28 +00:00 by michael · 0 comments
Owner

Originally created by @RemyyB on GitHub.

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

Originally created by @RemyyB on GitHub. 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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dutchcoders/transfer.sh#216