by AngelSalom » Mon May 29, 2006 8:38 pm
Con las clases nativas de FWH funciona muy bien.
/* ==========================================================================================
Func_Ftp
--------
Funciones para el manejo de FTP
Revisión : 04/04/2006 19:27
Revisado por : Angel
==========================================================================================
*/
#include "fivewin.ch"
Function Main()
Local oInternet, oFtp, cServFtp:="server",cUserFTp:="user",cPassFtp:="pass"
oInternet := TInternet():New()
oFTP := TFTP():New( Alltrim(cServFtp), oInternet, Alltrim(cUserFtp),Alltrim(cPassFtp) )
If ! Empty( oFTP:hFTP )
FtpSendFiles ({"file1.txt","file2.txt","file3.txt"},{"destfile1.txt","destfile2.txt","destfile3.txt"},oFtp)
Endif
oInternet:End()
Return (nil)
Function FTPSendFiles ( aSource, aTarget, oFTP )
Local nBufSize:=4096
local n
local hSource
local cBuffer := Space( nBufSize )
local nBytes, nFile := 0, nTotal := 0
local nTotSize := 0
local oFile
for n = 1 to Len( aSource )
if ! File( aSource[ n ] )
MsgStop( "Fichero no encontrado: " + aSource[ n ] )
exit
endif
hSource = FOpen( aSource[ n ] )
nTotSize += FSeek( hSource, 0, 2 )
FClose( hSource )
SysRefresh()
next
for n = 1 to Len( aSource )
hSource = FOpen( aSource[ n ] )
oFile = TFtpFile():New( aTarget[ n ], oFTP )
oFile:OpenWrite()
FSeek( hSource, 0, 0 )
nFile := 0
SysRefresh()
while ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0
oFile:Write( SubStr( cBuffer, 1, nBytes ) )
SysRefresh()
end
FClose( hSource )
oFile:End()
next
return nil
Function FtpGetFiles( aSource, aTarget, oFTP, oSay )
Local nBufSize:=4096
local n
local hTarget
local cBuffer := Space( nBufSize )
local nBytes, nFile := 0, nTotal := 0
local nTotSize := 0
local oFile, aFiles, aSizes := {}
for n = 1 to Len( aSource )
aFiles = oFTP:Directory( aSource[ n ] )
if Len( aFiles ) > 0
AAdd( aSizes, aFiles[ 1 ][ 2 ] ) // first file, size
nTotSize += ATail( aSizes )
else
AAdd( aSizes, 0 )
endif
SysRefresh()
next
nFile := 0
for n = 1 to Len( aSource )
hTarget = FCreate( aTarget[ n ] )
oFile = TFtpFile():New( aSource[ n ], oFTP )
oFile:OpenRead()
SysRefresh()
while ( nBytes := Len( cBuffer := oFile:Read( nBufSize ) ) ) > 0
FWrite( hTarget, cBuffer, nBytes )
If oSay<>NIL
oSay:SetText ("- Recibiendo :"+Str(nFile+=nBytes)+" de "+Str(nTotSize))
Endif
SysRefresh()
end
FClose( hTarget )
oFile:End()
next
return nil
No deberias tener problemas.
Angel Salom
Visionwin Software -
https://www.visionwin.com------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4