Have you example using liburl with scp:// ?
Posted: Mon Dec 21, 2020 1:36 am
Thanks!
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
EnableExplicit
#LibCurl_DLL$ = "libcurl.dll"
IncludeFile "libcurl.pbi"
ProcedureC.l my_fread(*buffer, Size, NMemB, fd)
Protected Result.i
Result = ReadData(fd, *buffer, (Size & 255) * NMemB)
Debug Str(Result) + " bytes read from file"
ProcedureReturn Result
EndProcedure
Define curl.i, fd.i, res.i, speed_upload.d, total_time.d
fd = ReadFile(#PB_Any, "scp.pb") ; open file to upload
If fd
curl = curl_easy_init()
If curl
; upload To this place
curl_easy_setopt_str(curl, #CURLOPT_URL, "scp://<my_host>:<my_port>/home/xxx/scp.pb")
; adjust user And password
curl_easy_setopt_str(curl, #CURLOPT_USERPWD, "<username>:<password>")
; tell it To "upload" To the URL
curl_easy_setopt(curl, #CURLOPT_UPLOAD, #True)
; set where To Read from (on Windows you need To use READFUNCTION too)
curl_easy_setopt(curl, #CURLOPT_READFUNCTION, @my_fread())
curl_easy_setopt(curl, #CURLOPT_READDATA, fd)
; And give the size of the upload (optional)
; curl_easy_setopt(curl, #CURLOPT_INFILESIZE_LARGE, Lof(fd))
; And give the size of the upload (optional)
curl_easy_setopt(curl, #CURLOPT_INFILESIZE, Lof(fd))
; accept insecure certificates
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, #False)
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, #False)
; enable verbose For easier tracing
curl_easy_setopt(curl, #CURLOPT_VERBOSE, #True)
res = curl_easy_perform(curl)
If res = #CURLE_OK
; now extract transfer info
curl_easy_getinfo(curl, #CURLINFO_SPEED_UPLOAD, @speed_upload)
curl_easy_getinfo(curl, #CURLINFO_TOTAL_TIME, @total_time)
Debug "Speed: " + StrD(speed_upload, 3) + " bytes/sec during " + StrD(total_time, 3) + " seconds"
Else
Debug "Error: " + curl_easy_strerror(res)
EndIf
; always cleanup
curl_easy_cleanup(curl)
EndIf
CloseFile(fd)
Else
Debug "Was not able to open file"
EndIf
infratec wrote:In windows you need the external libcurl.dll, since scp is not included in the internal libcurl.
Code: Select all
EnableExplicit #LibCurl_DLL$ = "libcurl.dll" IncludeFile "libcurl.pbi" ProcedureC.l my_fread(*buffer, Size, NMemB, fd) Protected Result.i Result = ReadData(fd, *buffer, (Size & 255) * NMemB) Debug Str(Result) + " bytes read from file" ProcedureReturn Result EndProcedure Define curl.i, fd.i, res.i, speed_upload.d, total_time.d fd = ReadFile(#PB_Any, "scp.pb") ; open file to upload If fd curl = curl_easy_init() If curl ; upload To this place curl_easy_setopt_str(curl, #CURLOPT_URL, "scp://<my_host>:<my_port>/home/xxx/scp.pb") ; adjust user And password curl_easy_setopt_str(curl, #CURLOPT_USERPWD, "<username>:<password>") ; tell it To "upload" To the URL curl_easy_setopt(curl, #CURLOPT_UPLOAD, #True) ; set where To Read from (on Windows you need To use READFUNCTION too) curl_easy_setopt(curl, #CURLOPT_READFUNCTION, @my_fread()) curl_easy_setopt(curl, #CURLOPT_READDATA, fd) ; And give the size of the upload (optional) ; curl_easy_setopt(curl, #CURLOPT_INFILESIZE_LARGE, Lof(fd)) ; And give the size of the upload (optional) curl_easy_setopt(curl, #CURLOPT_INFILESIZE, Lof(fd)) ; accept insecure certificates curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, #False) curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, #False) ; enable verbose For easier tracing curl_easy_setopt(curl, #CURLOPT_VERBOSE, #True) res = curl_easy_perform(curl) If res = #CURLE_OK ; now extract transfer info curl_easy_getinfo(curl, #CURLINFO_SPEED_UPLOAD, @speed_upload) curl_easy_getinfo(curl, #CURLINFO_TOTAL_TIME, @total_time) Debug "Speed: " + StrD(speed_upload, 3) + " bytes/sec during " + StrD(total_time, 3) + " seconds" Else Debug "Error: " + curl_easy_strerror(res) EndIf ; always cleanup curl_easy_cleanup(curl) EndIf CloseFile(fd) Else Debug "Was not able to open file" EndIf
Code: Select all
curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout)
Code: Select all
curl_easy_setopt(curl, #CURLOPT_TIMEOUT_MS, Timeout)
Code: Select all
Default timeout is 0 (zero) which means it never times out during transfer.
infratec wrote:You have so a high level, according to your ICs (or what else they should represent) on the left,
that I thought you are a master and you will know where you can get these files.![]()
If you are not such a master, then you can use this link:
https://www.von-der-salierburg.de/downl ... urldll.zip
You can set a timeout in seconds via:Or in ms:Code: Select all
curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout)
From:Code: Select all
curl_easy_setopt(curl, #CURLOPT_TIMEOUT_MS, Timeout)
https://curl.se/libcurl/c/CURLOPT_TIMEOUT.htmlCode: Select all
Default timeout is 0 (zero) which means it never times out during transfer.