Code: Select all
// Testing the FiveWin new Internet Classes
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local aFiles
local ctime1, ctime2
FTPGetFile( "127.0.0.1", "perla.dbf","sopas.dbf", "benji", "xxxx", 14147)
use sopas
browse()
return NIl
FUNCTION FtpSendFile( cFTPSite, cSource, cTarget, cUser, cPass, nBufSize )
LOCAL oInternet, oFTP
DEFAULT cUser:="", cPass:="", nBufSize:=2000
IF EMPTY(cFtpSite) .or. EMPTY(cSource) .or. EMPTY(cTarget)
MsgInfo("Missing Parameters"+chr(13)+"Usage: FtpSendFile(cFtpSite, cSource, cTarget, cUser, cPass, nBufSize) ","FtpSendFile()")
Return .f.
ENDIF
oInternet := TInternet():New()
IF Empty( oInternet:hSession )
MsgAlert( "Internet session not available!" )
ELSE
oFTP := TFTP():New( cFTPSite, oInternet, cUser, cPass )
IF Empty( oFTP:hFTP )
MsgStop( "Cannot connect to "+cFtpSite )
oInternet:End()
return .f.
ENDIF
ENDIF
SendFiles( cSource, cTarget, nBufSize, oFTP )
oInternet:End()
return nil
//----------------------------------------------------------------------------//
static function SendFiles( cSource, cTarget, nBufSize, oFTP )
local hSource
local cBuffer := Space( nBufSize )
local nBytes
local oFile
if ! File( cSource )
MsgStop( "File not found: " + cSource )
Return .f.
endif
hSource = FOpen( cSource )
oFile = TFtpFile():New( cTarget, oFTP )
oFile:OpenWrite()
FSeek( hSource, 0, 0 )
nFile := 0
while ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0
oFile:Write( SubStr( cBuffer, 1, nBytes ) )
end
FClose( hSource )
oFile:End()
return .t.
//----------------------------------------------------------------------------//
function FTPGetFile( cFTPSite, cSource, cTarget, cUser, cPass, nBufSize )
local oInternet, oFTP
DEFAULT cUser:="", cPass:="", nBufSize:=2000
IF EMPTY(cFtpSite) .or. EMPTY(cSource) .or. EMPTY(cTarget)
MsgInfo("Missing Parameters"+chr(13)+"Usage: FtpGetFile(cFtpSite, cSource, cTarget, cUser, cPass, nBufSize) ","FtpSendFile()")
Return .f.
ENDIF
oInternet := TInternet():New()
IF Empty( oInternet:hSession )
MsgAlert( "Internet session not available!" )
oInternet:End()
return .f.
ELSE
oFTP := TFTP():New( cFTPSite, oInternet, cUser, cPass )
if Empty( oFTP:hFTP )
MsgStop( "Cannot connect to "+cFtpSite)
oInternet:End()
return .f.
endif
ENDIF
GetFiles( cSource, cTarget, nBufSize, oFTP )
oInternet:End()
return .t.
//----------------------------------------------------------------------------//
static function GetFiles( cSource, cTarget, nBufSize, oFTP )
local hTarget
local cBuffer := Space( nBufSize )
local nBytes
local oFile, aFiles
hTarget = FCreate( cTarget )
oFile = TFtpFile():New( cSource, oFTP )
oFile:OpenRead()
while ( nBytes := Len( cBuffer := oFile:Read( nBufSize ) ) ) > 0
FWrite( hTarget, cBuffer, nBytes )
end
FClose( hTarget )
oFile:End()
return nil
//----------------------------------------------------------------------------//
function FtpIsFile(cFtpSite, cFile, cUser, cPass, lDelete)
local oInternet := TInternet():New()
local oFTP := TFTP():New( cFtpSite, oInternet, cUser, cPass )
local aFiles, lFound:=.f.
DEFAULT cUser := "", cPass:="", lDelete:=.f.
IF EMPTY(cFtpSite) .or. EMPTY(cFile)
Msginfo("Missing Parameters"+chr(13)+"Usage: CheckFtpFile(cFtpSite, cFile, cUser, cPass, lDelete) ","CheckFtpFile()")
Return .f.
ENDIF
IF ! Empty( oFTP:hFTP )
aFiles = oFTP:Directory( "*.*" )
AEval( aFiles, { | aFile | IIF( aFile[ 1 ] = cFile,(lFound:=lDeleted:=.t.), ) } )
ENDIF
if lDelete
if lFound
oFtp:deletefile(cFile)
msginfo("deleteed")
endif
endif
oInternet:End()
return lFound