FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FTP Best Options ?
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
FTP Best Options ?
Posted: Fri Mar 03, 2023 06:42 PM
I have been using cURL for JSON internet data transfers, and wininet.dll for file transfers. I've seen other examples here, and know the .dll interface is "older technology".

I am looking to update my interface for FTP uploads and downloads. I need to do the following:
  • Upload a file
    Download a file
    See what files are available on the server
    Delete a file on the server after downloading
I'm sure this is a familiar scenario. I would like to know what current methodologies are you using to accomplish these tasks. I am using FWH ( always latest version ), Harbour, MSVC 2020, with 32 and 64 bit builds.

Thanks for your suggestions.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: FTP Best Options ?
Posted: Sat Mar 04, 2023 02:16 AM
Hello Tim,

I am working on the same problem right now.
FTP should be replaced with secure FTP.
I don't have an example here yet.

For FTP I use the following function.

I wanted to change now unlike you to cURL: https:// and send with cURL.

curl --cacert /path/to/cacert.pem https://example.com

But I get this error: SSL certificate verify result: unable to get local issuer certificate (20)

Do you send with cURL and https?

Best regards,
Otto
Code (fw): Select all Collapse
function download()
   local oInternet := TInternet():New()
   local oFTP := TFTP():New( "192.168.0.230", oInternet,"remanco", "pwremanco" )
   local aFiles
   local handle
   *----------------------------------------------------------

   if ! Empty( oFTP:hFTP )

      FtpSetCurrentDirectory(oFTP:hFTP, "/usr/cheshire/boh/")

      aFiles = oFTP:Directory("rms.dat" )

      IF len(aFiles) > 0
            AEval( aFiles, { | aFile | FtpGetFile ( oFTP:hFTP, aFile[ 1 ], "c:\remanco\" + aFile[ 1 ] ,.t.,0,0,0 )  } )
      ENDIF

   else
        //  MsgAlert( "oFTP:hFTP is null" )
   endif

   oInternet:End()

return nil




function f_senden( cDatei )
   local oInternet := TInternet():New()
   local oFTP := TFTP():New( "ftp.test.info", oInternet, "salettainfo", "pwsaletta" )
   local aInfo := {}
   local I := 0
   local cAktivInfoDir := Setup():AppPath + "report" //Setup():Daten() + "\xReport"
 
   *----------------------------------------------------------

   if Empty( oFTP:hFTP )
      MsgStop( "Cannot connect to the specified FTP site!" )
      return nil
   endif



   if ! Empty( oFTP:hFTP )

      select EMPFAREP
      do while .not. eof()

            if  FTPPUTFILE(  oFTP:hFTP,  cAktivInfoDir + "\"+ cDatei, "/salettainfo/AktivInfo/1" + Alltrim(EMPFAREP->email)  , 0, 0 ) = .t.

            else
               msginfo("konnte nicht gesendet werden:   "   +   cAktivInfoDir + "\" + cDatei + CRLF +;
                  "/salettainfo/AktivInfo/" + cDatei  )
            endif

         select EMPFAREP
         skip
      enddo
   else

      MsgAlert( "oFTP:hFTP is null" )

   endif


   ferase (  cAktivInfoDir + "\" + cDatei)

   oInternet:End()
    logfile( "aktivInfo.log", {  "nach senden ", } )
return nil
//----------------------------------------------------------------------------//
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: FTP Best Options ?
Posted: Sat Mar 04, 2023 11:21 AM
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: FTP Best Options ?
Posted: Sun Mar 05, 2023 07:49 PM

I have reviewed the various options, and the pages Marc provided prior to making this post.

Otto, your example uses what was supposed to be the simplified tInternet class with tFTP. It works for obtaining a directory. HOWEVER, that class has no UPLOAD or DOWNLOAD methods.

SO ... I'm still hoping for more clarification or an answer to my question.

We are so dependent on the internet for conducting business that I would think this would be a priority for FiveWin.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: FTP Best Options ?
Posted: Sun Mar 05, 2023 09:51 PM

Hi Tim,

Can't you use ftpgetfile and ftpputfile as shown in my example?

Just out of interest: what do you want to send.

For example, I create reports and deliver them via email.

So far, I have always sent the data with ftp to a server and from there the emails.

Now I send directly from the customer server directly.

Or using mod harbour there are a several ways to send data to the server.

Best regards,

Otto

Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: FTP Best Options ?
Posted: Sun Mar 05, 2023 09:57 PM

Sorry, I didn't see them in there. I did find another sample that had them and appear to have it working now.

Thanks.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: FTP Best Options ?
Posted: Thu Mar 09, 2023 03:03 AM

Otto,

Is there a method to delete a file on the server ?

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: FTP Best Options ?
Posted: Thu Mar 09, 2023 08:15 AM

oConn:DropTable( "clientes" )

Just seen Otto.. This is for table inside a connectie. Otto is correct. Sorry

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: FTP Best Options ?
Posted: Thu Mar 09, 2023 08:56 AM
Hello Tim,
I use
Code (fw): Select all Collapse
 
FtpSetCurrentDirectory(oFTP:hFTP, "/meldemax")
aFiles = oFTP:Directory("*.*" )
xbrowse(aFiles)
IF len(aFiles) > 0

AEval( aFiles, { | aFile | msginfo( aFile[ 1 ] ),cFile := ALLTRIM( aFile[ 1 ] ),;
cFile := STRTRAN(UPPER(cFile),".TXT",".LTX"),; 

FtpGetFile (oFTP:hFTP,aFile[ 1 ], "c:\dbf\" + aFile[ 1 ] ,.t.,0,0,0 ) ,;

oFTP:DeleteFile( aFile[ 1 ]),;

endif
Best regards,
Otto
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM
Re: FTP Best Options ?
Posted: Wed Feb 12, 2025 01:03 PM
Hello everyone.
I am using this code from Otto to upload a file pdf to my ftp site.
Looks like the file is sended but with zero bytes. The file is showed when I open the directory by Filezila, but with zero bytes. And the function FTPPUTFILE returns false.
Any ideas?
Thanks in advance.
Otto wrote: Hello Tim,

I am working on the same problem right now.
FTP should be replaced with secure FTP.
I don't have an example here yet.

For FTP I use the following function.

I wanted to change now unlike you to cURL: https:// and send with cURL.

curl --cacert /path/to/cacert.pem https://example.com

But I get this error: SSL certificate verify result: unable to get local issuer certificate (20)

Do you send with cURL and https?

Best regards,
Otto
Code (fw): Select all Collapse
function download()
   local oInternet := TInternet():New()
   local oFTP := TFTP():New( "192.168.0.230", oInternet,"remanco", "pwremanco" )
   local aFiles
   local handle
   *----------------------------------------------------------

   if ! Empty( oFTP:hFTP )

      FtpSetCurrentDirectory(oFTP:hFTP, "/usr/cheshire/boh/")

      aFiles = oFTP:Directory("rms.dat" )

      IF len(aFiles) > 0
            AEval( aFiles, { | aFile | FtpGetFile ( oFTP:hFTP, aFile[ 1 ], "c:\remanco\" + aFile[ 1 ] ,.t.,0,0,0 )  } )
      ENDIF

   else
        //  MsgAlert( "oFTP:hFTP is null" )
   endif

   oInternet:End()

return nil




function f_senden( cDatei )
   local oInternet := TInternet():New()
   local oFTP := TFTP():New( "ftp.test.info", oInternet, "salettainfo", "pwsaletta" )
   local aInfo := {}
   local I := 0
   local cAktivInfoDir := Setup():AppPath + "report" //Setup():Daten() + "\xReport"
 
   *----------------------------------------------------------

   if Empty( oFTP:hFTP )
      MsgStop( "Cannot connect to the specified FTP site!" )
      return nil
   endif



   if ! Empty( oFTP:hFTP )

      select EMPFAREP
      do while .not. eof()

            if  FTPPUTFILE(  oFTP:hFTP,  cAktivInfoDir + "\"+ cDatei, "/salettainfo/AktivInfo/1" + Alltrim(EMPFAREP->email)  , 0, 0 ) = .t.

            else
               msginfo("konnte nicht gesendet werden:   "   +   cAktivInfoDir + "\" + cDatei + CRLF +;
                  "/salettainfo/AktivInfo/" + cDatei  )
            endif

         select EMPFAREP
         skip
      enddo
   else

      MsgAlert( "oFTP:hFTP is null" )

   endif


   ferase (  cAktivInfoDir + "\" + cDatei)

   oInternet:End()
    logfile( "aktivInfo.log", {  "nach senden ", } )
return nil
//----------------------------------------------------------------------------//
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#

Continue the discussion