Mastering TS Net

Sannyasin Brahmanathaswami brahma at hindu.org
Sun Jul 1 11:19:34 EDT 2018


I really need to get my head around TSNet, so began experiments.

This is the documentation for tsNetGetFile

" local tHeaders, tResult

put tsNetGetFile("1", "/path/to/downloaded/file.dat", \
"ftp://user:pass@ftp.example.com/file.dat", tHeaders, \
"transferComplete") into tResult

on transferComplete pID, pResult, pBytes, pCurlCode
	local tData, tHeaders
	if pCurlCode is not 0 then
		answer tsNetRetrError(pID)
	else
	a	nswer "File has been downloaded"
	end if
	tsNetCloseConn pID
end transferComplete

# but my first attempt to "get it" ... ran into this error. 

Are there any good lessons on all TSNet functions?
 I am not looking forward to wading into this blind as a bat.

# variable watcher

tResult      --        tsneterr: ID already in use

what is strange is this, the IDE gives the error even before tracing the mouseup.

So I did not even get off home plate.

############
local tHeaders, tResult

on mouseup 
# put a break here... the IDE show an error *before* stepping into the next statement
# I can't even close the connection with:
   tsNetCloseConn "1"
   put empty into tResult
   put fld aURL into pURL
   put empty into fld "fldHTTPHeader"
   put empty  into fld "tHTMLfield"
   set the itemDel to "/" 
   put item -1 of pURL into tFileName
   put ("~/Desktop/"&tFileName) into tLocalFile
   put tsNetGetFile("1",tLocalFile,pURL,tHeaders,"transferComplete") into tResult
 
   --  put libURLLastHTTPHeaders() into fld "fldHTTPHeader" 
end mouseup

on transferComplete pID, pResult, pBytes, pCurlCode
   if pCurlCode is not 0 then
      answer tsNetRetrError(pID)
   else
      answer "File has been downloaded"
      put tHeaders into fld "fldHTTPHeader"
   end if
   tsNetCloseConn pID
end transferComplete

BR




More information about the Use-livecode mailing list