FTP Bajar y Subir archivos

FTP Bajar y Subir archivos

Postby Dioni » Wed May 13, 2009 9:12 pm

Hola a todos.

No me esta funcionando las transferencias de archivos.
prodian decirme en que estoy equivocado.
mi direccion ftp es:

ftp.laquinta.com.pe

algunas lineas..

#include "FiveWin.ch"

function Main()
SET 3DLOOK ON
FTPSendFiles( "ftp.Laquinta.com.pe",{ "c:\dioni.dbf"}, {"httpdocs\data\dioni.dbf" } )
FTPGetFiles( "ftp.Laquinta.com.pe",{ "/httpdocs/data/dioni.dbf"},{ "c:\temp\dioni.dbf" } )
return nil
Dioni
 
Posts: 36
Joined: Tue May 12, 2009 8:45 pm
Location: Lima - Perú

Re: FTP Bajar y Subir archivos

Postby Daniel Garcia-Gil » Thu May 14, 2009 6:42 am

Hola Dionicio...

te genera algun error?

de ser si.... muestralo por favor
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: FTP Bajar y Subir archivos

Postby Dioni » Sun May 24, 2009 1:36 pm

Hola Daniel
Gracias por tu interes de ayudarme.
Pero te cuento encontre algunos ejemplos y pude aprovechar de ellos.
aqui la solucion:

Para ello deberan de contar con un dominio "www.demofwh.com" etc. el cual se consigue
contratando un servidor de un dominio.

Buscar en las facturas que nos entrego el proveedor del Dominio el Usuario ????? , Password ????????
que van a ser necesarios para que funciones este ejemplo.

Con este dominio podran contar:

correos con el nombre de dominio
FTP espacio para guardar archivos <--- aqui es donde se crea una carpeta "httpdocs/data2009" segun el ejemplo.
colgar paginas Webs

Espero que les sirvan a algunos colegas que estan iniciandose en FWH.
Estas lineas de programa viene como ejemplo en FWH

Ejemplo:

#include "FiveWin.ch"
* Archivo a enviar con que nombre se va a guardar
function Main() // │ │
SET 3DLOOK ON // v v
FTPSendFiles("ftp.Laquinta.com.pe",{"c:\dioni.zip"},{"/httpdocs/data2009/chura1.zip"})



* Archivo de FTP archivo a guardar

FTPGetFiles( "ftp.Laquinta.com.pe",{"/httpdocs/data2009/chura1.zip"},{"c:\saraq1.zip"})
return nil

function FTPSendFiles( cFTPSite, aSource, aTarget )
local oDlg, oSay1, oSay2, oSay3, oBtnCancel
local oMeter1, oMeter2
local nAmount1, nAmount2
local lEnd := .f.
local nBufSize := 4096 //2000
local oInternet, oFTP
MsgRun( "Connecting to FTP...", "Please, wait",{ || oInternet := TInternet():New(),;
If( Empty( oInternet:hSession ),MsgAlert( "Internet session not available!" ),),;
oFTP := TFTP():New( "ftp.xxxxxxxx.com.pe", oInternet,"aaaaaaaaa","bbbbbbbbbb" )}) //usuario , password ok
if Empty( oFTP:hFTP )
MsgStop( "Cannot connect to the specified FTP site!" )
return nil
endif
DEFINE DIALOG oDlg RESOURCE "ICopyFiles" TITLE "Subiendo Informacion a : " + cFTPSite
REDEFINE SAY oSay1 ID 110 OF oDlg
REDEFINE SAY oSay2 ID 120 OF oDlg
REDEFINE METER oMeter1 VAR nAmount1 ID 130 OF oDlg
REDEFINE SAY oSay3 ID 140 OF oDlg
REDEFINE METER oMeter2 VAR nAmount2 ID 150 OF oDlg
REDEFINE BUTTON oBtnCancel ID 2 OF oDlg ACTION ( lEnd := .t., SysRefresh(), oDlg:End() )
oDlg:bStart := { || SendFiles( aSource, aTarget, nBufSize,oSay1, oSay2, oMeter1, oSay3, oMeter2,@lEnd, oDlg, oFTP ),oBtnCancel:SetText( "&Ok" ) }
ACTIVATE DIALOG oDlg CENTERED
oInternet:End()
return nil

static function SendFiles( aSource, aTarget, nBufSize, oSay1, oSay2,oMeter1, oSay3, oMeter2, lEnd, oDlg, 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( "File not found: " + aSource[ n ] )
oDlg:End()
exit
endif
hSource = FOpen( aSource[ n ] )
nTotSize += FSeek( hSource, 0, 2 )
FClose( hSource )
SysRefresh()
next
oMeter2:nTotal = nTotSize
for n = 1 to Len( aSource )
hSource = FOpen( aSource[ n ] )
oFile = TFtpFile():New( aTarget[ n ], oFTP )
oFile:OpenWrite()
oSay1:SetText( "Source: " + aSource[ n ] )
oSay2:SetText( "Target: " + aTarget[ n ] )
oMeter1:Set( 0 )
oMeter1:nTotal = FSeek( hSource, 0, 2 )
FSeek( hSource, 0, 0 )
nFile := 0
SysRefresh()
while ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0 .and. ! lEnd
oFile:Write( SubStr( cBuffer, 1, nBytes ) )
oSay3:SetText( "Bytes copied: " +AllTrim( Str( nTotal += nBytes ) ) )
oMeter1:Set( nFile += nBytes )
oMeter2:Set( nTotal )
SysRefresh()
end
FClose( hSource )
oFile:End()
if lEnd
exit
endif
next
return nil

function FTPGetFiles( cFTPSite, aSource, aTarget )
local oDlg, oSay1, oSay2, oSay3, oBtnCancel
local oMeter1, oMeter2
local nAmount1, nAmount2
local lEnd := .f.
local nBufSize := 4096 //2000
local oInternet, oFTP
MsgRun( "Connecting to FTP...", "Please, wait",{ || oInternet := TInternet():New(),;
oFTP := TFTP():New( "ftp.xxxxxxxx.com.pe", oInternet,"aaaaaaaaa","bbbbbbbbbb" )}) //usuario , password ok
if Empty( oFTP:hFTP )
MsgStop( "Cannot connect to the specified FTP site!" )
return nil
endif
DEFINE DIALOG oDlg RESOURCE "ICopyFiles" TITLE "Bajando Informacion de : " + cFTPSite
REDEFINE SAY oSay1 ID 110 OF oDlg
REDEFINE SAY oSay2 ID 120 OF oDlg
REDEFINE METER oMeter1 VAR nAmount1 ID 130 OF oDlg
REDEFINE SAY oSay3 ID 140 OF oDlg
REDEFINE METER oMeter2 VAR nAmount2 ID 150 OF oDlg
REDEFINE BUTTON oBtnCancel ID 2 OF oDlg ACTION ( lEnd := .t., SysRefresh(), oDlg:End() )
oDlg:bStart := { || GetFiles( aSource, aTarget, nBufSize,oSay1, oSay2, oMeter1, oSay3, oMeter2,@lEnd, oDlg, oFTP ),oBtnCancel:SetText( "&Ok" )}
ACTIVATE DIALOG oDlg CENTERED
oInternet:End()
return nil

static function GetFiles( aSource, aTarget, nBufSize, oSay1, oSay2,oMeter1, oSay3, oMeter2, lEnd, oDlg, oFTP)
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
oMeter2:nTotal = nTotSize
for n = 1 to Len( aSource )
hTarget = FCreate( aTarget[ n ] )
oFile = TFtpFile():New( aSource[ n ], oFTP )
oFile:OpenRead()
oSay1:SetText( "Source: " + aSource[ n ] )
oSay2:SetText( "Target: " + aTarget[ n ] )
oMeter1:Set( 0 )
oMeter1:nTotal = aSizes[ n ]
nFile := 0
SysRefresh()
while ( nBytes := Len( cBuffer := oFile:Read( nBufSize ) ) ) > 0 .and. ! lEnd
FWrite( hTarget, cBuffer, nBytes )
oSay3:SetText( "Bytes copied: " + ;
AllTrim( Str( nTotal += nBytes ) ) )
oMeter1:Set( nFile += nBytes )
oMeter2:Set( nTotal )
SysRefresh()
end
FClose( hTarget )
oFile:End()
if lEnd
exit
endif
next
return nil


Send_rec.rc

#define ICON_1 1
#include "..\include\WinApi.ch"
#ifdef __FLAT__
1 24 "WinXP/WindowsXP.Manifest"
#endif

#ifdef __64__
1 24 "WinXP/WindowsXP.Manifest64"
#endif

ICopyFiles DIALOG 29, 85, 250, 140
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Copy Files"
FONT 8, "MS Sans Serif"
{
GROUPBOX "Current file", -1, 40, 4, 180, 46, BS_GROUPBOX
LTEXT "Source:", 110, 46, 15, 157, 8
LTEXT "Target:", 120, 47, 25, 157, 8
CONTROL "", 130, "TMeter", 0 | WS_CHILD | WS_VISIBLE, 45, 35, 168,11
GROUPBOX "Total", -1, 40, 60, 180, 46, BS_GROUPBOX
LTEXT "Bytes copied:", 140, 46, 73, 157, 8
CONTROL "", 150, "TMeter", 0 | WS_CHILD | WS_VISIBLE, 45, 83, 168, 11
PUSHBUTTON "Cancel", IDCANCEL, 94, 120, 38, 14
ICON "copfiles", -1,7,20, 18, 20
}

copfiles ICON "../icons/copyfile.ico"
Dioni
 
Posts: 36
Joined: Tue May 12, 2009 8:45 pm
Location: Lima - Perú


Return to FiveWin para Harbour/xHarbour

Who is online

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