ayuda como subir archivo via ftp

ayuda como subir archivo via ftp

Postby lafug » 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
User avatar
lafug
 
Posts: 185
Joined: Thu Nov 17, 2005 12:48 am
Location: Santiago, Chile

Re: ayuda como subir archivo via ftp

Postby Manuel Valdenebro » Fri Dec 09, 2011 3: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
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Re: ayuda como subir archivo via ftp

Postby postinelli » 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
//----------------------------------------------------------------------------//
postinelli
 
Posts: 147
Joined: Tue Jul 15, 2008 7:12 pm
Location: Argentina

Re: ayuda como subir archivo via ftp

Postby lafug » Sat Dec 10, 2011 1: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
User avatar
lafug
 
Posts: 185
Joined: Thu Nov 17, 2005 12:48 am
Location: Santiago, Chile


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests