Page 1 of 1

SFTP upload

Posted: Tue Jul 25, 2017 9:21 pm
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

Re: SFTP upload

Posted: Tue Jul 25, 2017 9:57 pm
by edk
I think this is possible using hbcUrl lib.
https://harbour.github.io/contribs
https://curl.haxx.se/libcurl/

Re: SFTP upload

Posted: Wed Jul 26, 2017 7:03 am
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

Re: SFTP upload

Posted: Wed Jul 26, 2017 9:00 am
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.

Re: SFTP upload

Posted: Wed Jul 26, 2017 9:57 am
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 :)

Re: SFTP upload

Posted: Wed Jul 26, 2017 10:34 am
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

Re: SFTP upload

Posted: Wed Jul 26, 2017 12:20 pm
by mlnr
Thank you, Edward. This is more complex than my test code snippet.

Re: SFTP upload

Posted: Wed Jul 26, 2017 10:55 pm
by Georg_BA
Thank you EDK really great.
Thumb up.

Re: SFTP upload

Posted: Wed Jul 26, 2017 11:37 pm
by Georg_BA
For compilations, add them to SFTP.HBC

libs=hbcurls
libs=hbcurl
libs=libcurl