[FUNC] transfer.sh

Post your working scripts, libraries and tools
User avatar
TheDewd
Posts: 1190
Joined: 19 Dec 2013, 11:16
Location: USA

[FUNC] transfer.sh

29 Jun 2018, 16:08

transfer.sh
https://www.transfer.sh/

Function for uploading files to the transfer.sh file hosting service.


Examples
Upload a single file:

Code: Select all

MsgBox, % TransferSH("File1.txt")
Upload a single file with custom filename:

Code: Select all

MsgBox, % TransferSH("File1.txt<ThisIsMyCustomName.txt>")
Upload a single file with a maximum download limit and maximum storage duration:

Code: Select all

MsgBox, % TransferSH("File1.txt", "1", "5") ; 1 Download / 5 Days
Upload multiple files:

Code: Select all

Downloads := ""

Loop, Files, C:\Users\UserName\Downloads\*.txt, F
{
	Downloads .= (A_Index = 1 ? "" : "`n") TransferSH(A_LoopFileLongPath)
}

MsgBox, % Downloads
Upload multiple files and download as zip archive

Code: Select all

Downloads := ""

Loop, Files, C:\Users\UserName\Downloads\*.txt, F
{
	Downloads .= (A_Index = 1 ? "" : ",") StrReplace(TransferSH(A_LoopFileLongPath), "https://transfer.sh", "")
}

MsgBox, % "https://transfer.sh/(" Downloads ").zip"
Function

Code: Select all

TransferSH(Filename, MaxDownloads := "", MaxDays := "") {
	File := FileOpen(RegExReplace(Filename, "<(.*?)>"), "r")
	Body := ComObjArray(0x11, File.Length)
	Data := NumGet(ComObjValue(Body) + 12 + (A_PtrSize = 8 ? 4 : 0))
	File.RawRead(Data + 0, File.Length)
	File.Close()
	
	RegExMatch(Filename, "<(.*?)>", Name)
	SplitPath, Filename, FilenameExt

	HttpReq := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	HttpReq.Open("PUT", "https://transfer.sh/" (Name1 ? Name1 : FilenameExt))
	HttpReq.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

	If (MaxDownloads) {
		HttpReq.SetRequestHeader("Max-Downloads", "" MaxDownloads "")
	}

	If (MaxDays) {
		HttpReq.SetRequestHeader("Max-Days", "" MaxDays "")
	}

	HttpReq.SetTimeouts(0, 60000, 30000, 120000)
	HttpReq.Send(Body)
	HttpReq.WaitForResponse()

	return HttpReq.ResponseText
}
Last edited by TheDewd on 02 Jul 2018, 11:15, edited 2 times in total.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
burque505
Posts: 861
Joined: 22 Jan 2017, 19:37

Re: [FUNC] transfer.sh

29 Jun 2018, 17:40

Thanks for sharing this, it works well. I tried all the examples. To my surprise, the last one with the zip archive executed much faster than the rest!
It should definitely come in handy.
Regards,
burque505
Ved
Posts: 9
Joined: 15 Jul 2016, 19:06

Re: [FUNC] transfer.sh

29 Jun 2018, 17:49

GREAT !!!

Return to “Scripts and Functions”

Who is online

Users browsing this forum: blue83, Lastresort and 46 guests