Since several days i fighting with the LibCurl
Thanks to INFRATEC i can now :
1/ Read the list of elements of a folder => DirList()
2/ Put a file in the remote folder
But when i want refresh the list, i call a new time the DirList() procedure, and that not works
I have the return
There are surely a variable bad used, or not initialized, but i don't find whereLibCurl wrote:Error: Error in the SSH layer
If someone understand the problem, because i believe i coming crazy
Code: Select all
#LibCurl_ExternalDLL = #True
IncludeFile "libcurl.pbi"
Global curl.i, res.i, Url$
Global UserData.libcurl_userdata_structure
#REMOTE_URL = "sftp://MyFtpServer.fr/var/www/html/"
#Username$ = "XXXX"
#Password$ = "XXXXX"
InitNetwork()
curl_global_init(#CURL_GLOBAL_DEFAULT)
curl = curl_easy_init()
curl_easy_setopt_str(curl, #CURLOPT_USERNAME, #Username$)
curl_easy_setopt_str(curl, #CURLOPT_PASSWORD, #Password$)
Procedure DirList()
curl_easy_setopt_str(curl, #CURLOPT_URL, #REMOTE_URL)
curl_easy_setopt(curl, #CURLOPT_FTP_USE_EPSV, 0)
curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @LibCurl_WriteFunction())
curl_easy_setopt(curl, #CURLOPT_WRITEDATA, @UserData)
curl_easy_setopt(curl, #CURLOPT_USE_SSL, #CURLUSESSL_ALL)
curl_easy_setopt(curl, #CURLOPT_FTPSSLAUTH, #CURLFTPAUTH_TLS)
; accept insecure certificates
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, #False)
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, #False)
curl_easy_setopt(curl, #CURLOPT_VERBOSE, #True)
res = curl_easy_perform(curl)
If res = #CURLE_OK
Debug "Ok"
Debug PeekS(UserData\Memory, MemorySize(UserData\Memory), #PB_UTF8|#PB_ByteLength)
Else
Debug "Error: " + curl_easy_strerror(res)
EndIf
EndProcedure
If curl
DirList()
#LOCAL_FILE = "C:\Windows\Win.ini"
#REMOTE_FILE = "Win.ini"
UserData\File = ReadFile(#PB_Any, #LOCAL_FILE)
If UserData\File
*headerlist = curl_slist_append(*headerlist, "RNFR " + #REMOTE_FILE)
curl_easy_setopt(curl, #CURLOPT_READFUNCTION, @LibCurl_ReadFunction())
curl_easy_setopt(curl, #CURLOPT_READDATA, @UserData)
curl_easy_setopt(curl, #CURLOPT_UPLOAD, 1)
curl_easy_setopt_str(curl, #CURLOPT_URL, #REMOTE_URL + #REMOTE_FILE)
curl_easy_setopt(curl, #CURLOPT_POSTQUOTE, *headerlist)
; optional
curl_easy_setopt(curl, #CURLOPT_INFILESIZE, Lof(UserData\File))
curl_easy_setopt(curl, #CURLOPT_USE_SSL, #CURLUSESSL_ALL)
; accept insecure certificates
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, #False)
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, #False)
res = curl_easy_perform(curl)
If res = #CURLE_OK
Debug "Ok"
Else
Debug "Error: " + curl_easy_strerror(res)
EndIf
curl_slist_free_all(*headerlist)
CloseFile(UserData\File)
DirList()
curl_easy_cleanup(curl)
curl_global_cleanup()
EndIf
EndIf


