SFTP upload

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
Georg_BA
Posts: 36
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF
Been thanked: 1 time

SFTP upload

Post by Georg_BA » Tue Jul 25, 2017 9:21 pm

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: 415
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 123 times
Been thanked: 331 times

Post by edk » Tue Jul 25, 2017 9:57 pm

I think this is possible using hbcUrl lib.
https://harbour.github.io/contribs
https://curl.haxx.se/libcurl/

Georg_BA
Posts: 36
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF
Been thanked: 1 time

Post by Georg_BA » Wed Jul 26, 2017 7:03 am

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: 85
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF
Location: Hungary
Has thanked: 26 times
Been thanked: 9 times

Post by mlnr » 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.
Best regards,
Gabor

Georg_BA
Posts: 36
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF
Been thanked: 1 time

Post by Georg_BA » Wed Jul 26, 2017 9:57 am

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: 415
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 123 times
Been thanked: 331 times

Post by edk » Wed Jul 26, 2017 10:34 am

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 163 times

mlnr
Posts: 85
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF
Location: Hungary
Has thanked: 26 times
Been thanked: 9 times

Post by mlnr » Wed Jul 26, 2017 12:20 pm

Thank you, Edward. This is more complex than my test code snippet.
Best regards,
Gabor

Georg_BA
Posts: 36
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF
Been thanked: 1 time

Post by Georg_BA » Wed Jul 26, 2017 10:55 pm

Thank you EDK really great.
Thumb up.

Georg_BA
Posts: 36
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF
Been thanked: 1 time

Post by Georg_BA » Wed Jul 26, 2017 11:37 pm

For compilations, add them to SFTP.HBC

libs=hbcurls
libs=hbcurl
libs=libcurl

Post Reply