FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour ayuda como subir archivo via ftp
Posts: 185
Joined: Thu Nov 17, 2005 12:48 AM
ayuda como subir archivo via ftp
Posted: Fri Dec 09, 2011 12:52 AM

Estimados,

necesito enviar un archivo desde mi aplicación FW vía FTP a un servidor que tengo funcionando, pero no he conseguido implementarlo, cual sería la forma más sencilla y práctica y que clase debo usar?

de antemano gracias por sus respuestas

Luis Alfonso Fuentes Guerrero

FWH 11.06 xHarbour 1.2.1 BCC55 WorkShop
Posts: 711
Joined: Thu Oct 06, 2005 09:57 PM
Re: ayuda como subir archivo via ftp
Posted: Fri Dec 09, 2011 03:01 AM

Yo lo hago usando las funciones nativas de Window de Wininet. Este es el código:

include "wininet.ch"

// cFtpAddress nombre del host (ftp.fivewin.com)
// cUser Usuario del Host
// cPass Password del Host
// cOrige path origen, (csv/pepe1.txt)
// cDestino path destino (/html/csv/pepe2.txt)

FUNCTION SubirFtp( cFtpAddress, cUser, cPass, cOrigen, cDestino )
local hWinInet, hInternet, hConnect, lOk

// cargamos la DLL si no estaba cargada
hWinINet := WinINet()

if hWinINet < 0 .or. hWinINet >= 32
      hInternet := InternetOpen( "ftp", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
   endif

hConnect := INTERNETCONNECT( hInternet, cFtpAddress, 21, cUser, cPass, 1, 0, 0 )

IF hconnect == 0
      alert ("ERROR EN CONEXION.")
   ELSE
      TRY
         lOk := FTPPUTFILE( hConnect, cOrigen, cDestino, 0, 0 )
         alert (lOk)
      CATCH
         alert ("Error FTP.")
      END

ENDIF

INTERNETCLOSEHANDLE( hConnect )

INTERNETCLOSEHANDLE( hInternet )

RETURN nil

Un saludo



Manuel
Posts: 150
Joined: Tue Jul 15, 2008 07:12 PM
Re: ayuda como subir archivo via ftp
Posted: Fri Dec 09, 2011 12:10 PM

así lo hago yo, con FiveWin y xHarbour

MsgRun( "Enviando Datos por Ftp...", "Ftp",;
{ || FtpSend(salida,cServerFtp,cUserFtp,cPassFtp) } )

//----------------------------------------------------------------------------//
Function FTPSendFiles( cFTPSite, aSource, aTarget, cUserFtp, cPassFtp )

Local lEnd := .f.
Local nBufSize := 2000
Local oInternet, oFTP

MsgRun( "Conectando al Sitio FTP...", "Espere...",;
{ || oInternet := TInternet():New(),;
If( Empty( oInternet:hSession ),;
MsgAlert( "Sin Conexión a Internet!" ),),;
oFTP := TFTP():New( cFTPSite, oInternet, Alltrim(cUserFtp),Alltrim(cPassFtp) ) } )

if Empty( oFTP:hFTP )
MsgStop( "Imposible Conectarse al Sito FTP!" )
return nil
endif

SendFiles( aSource, aTarget, nBufSize, lEnd, oFTP )

oInternet:End()

return nil
//----------------------------------------------------------------------------//
Static Function SendFiles( aSource, aTarget, nBufSize, lEnd, oFTP )

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( "Archivo No Encontrado: " + aSource[ n ] )
exit
endif
hSource = FOpen( aSource[ n ] )
nTotSize += FSeek( hSource, 0, 2 )
FClose( hSource )
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
while ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0 .and. ! lEnd
oFile:Write( SubStr( cBuffer, 1, nBytes ) )
end
FClose( hSource )
oFile:End()
if lEnd
exit
endif
next
Return nil
//----------------------------------------------------------------------------//

Posts: 185
Joined: Thu Nov 17, 2005 12:48 AM
Re: ayuda como subir archivo via ftp
Posted: Sat Dec 10, 2011 01:51 PM

Gracias por sus respuestas Amigos! voy a probar.

un Abrazo

Luis Alfonso Fuentes Guerrero

FWH 11.06 xHarbour 1.2.1 BCC55 WorkShop

Continue the discussion