Browse Ftp files

Browse Ftp files

Postby StefanHaupt » Fri Nov 30, 2012 3:14 pm

Hi all,

I try to list all files in a ftp dir in xbrowse

But I get for every filename only "binary" instead of the filename, MsgInfo (aFiles[1,1]) shows the correct filename

Code: Select all  Expand view
oInternet := tInternet():New()
     oFtp      := tFtp():New (cIp, oInternet, cUser, cPW)

     IF Empty (oFtp:hFtp)
       ? "Ftp failed"
     ELSE

       cFile := GetModuleFileName( GetInstance() )

       oFtp:SetCurrentDirectory( cFolder )
       aFiles := oFtp:Directory ('*.*')
       aFiles := ADel (aFiles,1,.t.)  // remove .
       aFiles := ADel (aFiles,1,.t.)  // remove ..
        
       ? Len (aFiles), aFiles [1,1]  // works correct
       xBrowser aF


Any hints ?
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Browse Ftp files

Postby StefanHaupt » Thu Dec 06, 2012 1:52 pm

Antonio,

please, could you look at this sample.

Code: Select all  Expand view
// Testing the FiveWin new Internet Classes

#include "FiveWin.ch"
#include "xBrowse.ch"

//----------------------------------------------------------------------------//

function Main()

   local cFtp := "xxxx"
   local cUser := "xxxxx"
   local cPass := "xxxxx"

   local oInternet := TInternet():New()
   local oFTP      := TFTP():New( cFtp, oInternet, cUser,cPass ) // Microsoft FTP
   local aFiles

   if ! Empty( oFTP:hFTP )
      aFiles = oFTP:Directory( "*.*" )
      AEval( aFiles, { | aFile | MsgInfo( aFile[ 1 ], aFile[ 3 ] ) } )
   else
      MsgAlert( "oFTP:hFTP is null" )
   endif

   oInternet:End()

   MsgInfo( "Done!" )

   xBrowser aFiles

return nil
 

MsgInfo (...) is working fine, but why does xBrowse think, it´s a raw file ?

Also all string functions (Substr(), Len (), Alltrim(), ...) do not work. Even Valtype () returns nothing. What kind of datatype is it ?

Image

Uploaded with ImageShack.us
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Browse Ftp files

Postby StefanHaupt » Tue Dec 11, 2012 9:08 am

OK, after some investigation I found it :)

oFTP:Directory( "*.*" ) return a nul-terminated string for the filename. In another sample I found this function to extract a normal string

Code: Select all  Expand view
#define ZTRIM( cString ) Left( cString, At( Chr( 0 ), cString ) - 1 )
 AEval (aFiles, {|x| Aadd (aF, {ZTRIM (x[1]), x[2], x[3] } )} )
       xBrowser aF


this is working fine now.

Antonio,

just a suggestion, maybe it´s useful to enhance the the method Directory() in the class TFtp as follows

Code: Select all  Expand view
#define ZTRIM( cString ) Left( cString, At( Chr( 0 ), cString ) - 1 )

METHOD Directory( cMask ) CLASS TFTP
   ....
   ....
      if ::hFTP != nil
      cBuffer = oWin32FindData:cBuffer
      hFTPDir = FtpFindFirstFile( ::hFTP, cMask, @cBuffer, 0, 0 )
      oWin32FindData:cBuffer = cBuffer
      if ! Empty( oWin32FindData:cFileName )
         AAdd( aFiles, { ZTRIM (oWin32FindData:cFileName),;    // change !!
                         oWin32FindData:nSizeLow,;
                         FileTimeToDate( oWin32FindData:nLastWriteAccess ),;
                         FileTimeToTime( oWin32FindData:nLastWriteAccess ) } )
         while InternetFindNextFile( hFTPDir, @cBuffer )
            oWin32FindData:cBuffer = cBuffer
            AAdd( aFiles, { ZTRIM (oWin32FindData:cFileName),;   // change !!
                            oWin32FindData:nSizeLow,;
                            FileTimeToDate( oWin32FindData:nLastWriteAccess ),;
                            FileTimeToTime( oWin32FindData:nLastWriteAccess ) } )
         end
      endif
      InternetCloseHandle( hFTPDir )
   endif

return aFiles


What do you think ?
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Browse Ftp files

Postby StefanHaupt » Tue Dec 11, 2012 12:56 pm

another enhancement to read the current directory of the ftp-server

Maybe it can be included in the next fwh-version, too.

in wininet.prg
Code: Select all  Expand view
DLL32 FUNCTION FtpGetCurrentDirectory( hFTP AS LONG, @cDirName AS LPSTR, @nLength AS LONG ) ;
                              AS BOOL PASCAL ;
                              FROM "FtpGetCurrentDirectoryA" LIB hWinINet


in tftp.prg
Code: Select all  Expand view
METHOD GetCurrentDirectory()
....
....
//----------------------------------------------------------------------------//

METHOD GetCurrentDirectory ()

  LOCAL lSuccess := .t.
  LOCAL cDirName := Space (1024 )

  lSuccess := FtpGetCurrentDirectory( ::hFTP, @cDirName, Len (cDirName) )

RETURN ( IIF (lSuccess, cDirName, "") )
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 93 guests

cron