SFTP upload

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
Georg_BA
Posts: 106
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

SFTP upload

Post by Georg_BA »

Nice day all
I needed to help upload the file to the SFTP server
In the forums, I have seen only classic FTP without security
Thanks for help
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: SFTP upload

Post by edk »

I think this is possible using hbcUrl lib.
https://harbour.github.io/contribs
https://curl.haxx.se/libcurl/
Georg_BA
Posts: 106
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Re: SFTP upload

Post by Georg_BA »

Thanks for help
I will look at the functions of the lib.
If you use the lib, you could provide a sample code
Best Regards Georg
mlnr
Posts: 126
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF

Re: SFTP upload

Post by mlnr »

Hello,

Yes, it works with CURL. I've been trying for more than a year.

Code: Select all

fm:="test"
If ! Empty( curl := curl_easy_init() )
  hb_default( @cUL, "sftp://demo:demo@ftp-server.demo.solarwinds.com/upload/TEST.TXT" )
  curl_easy_setopt( curl, HB_CURLOPT_URL, cUL )
  curl_easy_setopt( curl, HB_CURLOPT_UPLOAD)
  curl_easy_setopt( curl, HB_CURLOPT_PROTOCOLS, HB_CURLPROTO_SFTP )	  
  curl_easy_setopt( curl, HB_CURLOPT_UL_FILE_SETUP, "C:\1\TEST.TXT" )
  curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE, len(fm) )
  curl_easy_perform( curl )
  curl_easy_reset( curl )
  curl_easy_cleanup( curl )
Endif
curl_global_cleanup()
And you can test with online demo SFTP/FTP server, if you need http://ftp-server.demo.solarwinds.com/
id: demo
psw: demo

You will find more help on the forum for CURL if you need it.
Best regards,
Gabor
Georg_BA
Posts: 106
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Re: SFTP upload

Post by Georg_BA »

Thank you very much. I'll test it.
I have tried to search the forum under ftp sftp and have found nothing relevant.
I did not think of entering CURL :)
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: SFTP upload

Post by edk »

mlnr wrote: Wed Jul 26, 2017 9:00 am Hello,

Yes, it works with CURL. I've been trying for more than a year.

Code: Select all

fm:="test"
If ! Empty( curl := curl_easy_init() )
  hb_default( @cUL, "sftp://demo:demo@ftp-server.demo.solarwinds.com/upload/TEST.TXT" )
  curl_easy_setopt( curl, HB_CURLOPT_URL, cUL )
  curl_easy_setopt( curl, HB_CURLOPT_UPLOAD)
  curl_easy_setopt( curl, HB_CURLOPT_PROTOCOLS, HB_CURLPROTO_SFTP )	  
  curl_easy_setopt( curl, HB_CURLOPT_UL_FILE_SETUP, "C:\1\TEST.TXT" )
  curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE, len(fm) )
  curl_easy_perform( curl )
  curl_easy_reset( curl )
  curl_easy_cleanup( curl )
Endif
curl_global_cleanup()
And you can test with online demo SFTP/FTP server, if you need http://ftp-server.demo.solarwinds.com/
id: demo
psw: demo

You will find more help on the forum for CURL if you need it.
Almost true, but this is wrong:

Code: Select all

curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE, len(fm) )
should be:

Code: Select all

curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE, FILESIZE("C:\1\TEST.TXT") )
In the attachment you have a working demo with all the needed dlls and libs.
Copy the files from the "dll" folder to "c:\hmg.3.4.4\HARBOUR\lib\win\mingw\", where: "c:\hmg.3.4.4" is the location of HMG 3.4.4.
Tested on local SFTP Bitvise SSH Server and HMG 3.4.4
Attachments
sftp.7z
(2.34 MiB) Downloaded 424 times
mlnr
Posts: 126
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF

Re: SFTP upload

Post by mlnr »

Thank you, Edward. This is more complex than my test code snippet.
Best regards,
Gabor
Georg_BA
Posts: 106
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Re: SFTP upload

Post by Georg_BA »

Thank you EDK really great.
Thumb up.
Georg_BA
Posts: 106
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Re: SFTP upload

Post by Georg_BA »

For compilations, add them to SFTP.HBC

libs=hbcurls
libs=hbcurl
libs=libcurl
Post Reply