Page 1 of 1

FTP ???

Posted: Tue Jun 07, 2011 7:08 pm
by Mayor_Valenzuela
Hola nuevamente...

Manejo muy bien el tema del FTP, puedo subir y bajar archivos pero que pasa cuando los necesito bajar y eliminar???

Si alguien tiene una idea... Uso


DLL32 FUNCTION FTPGETFILE( hConnect AS LONG, cRemoteFile AS LPSTR, cNewFile AS LPSTR, nFailIfExists AS LONG, nFlagsAndAttribs AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS BOOL;
PASCAL FROM "FtpGetFileA" LIB "wininet.dll"

DLL32 FUNCTION FTPPUTFILE( hConnect AS LONG, cLocalFile AS LPSTR, cNewRemoteFile AS LPSTR, nFlags AS DWORD, @nContext AS PTR ) AS BOOL;
PASCAL FROM "FtpPutFileA" LIB "wininet.dll"

Para descargar subir un archivo y ahora necito eliminar el que descarge...

Re: FTP ???

Posted: Tue Jun 07, 2011 7:48 pm
by Manuel Valdenebro
Comprueba si te funciona esto:

DLL32 FUNCTION FtpDeleteFile( hFTP AS LONG, cFileName AS LPSTR ) AS BOOL PASCAL ;
FROM "FtpDeleteFileA" LIB hWinINet

Re: FTP ???

Posted: Wed Jun 08, 2011 12:45 pm
by Mayor_Valenzuela
Muchisimas gracias... la verdad que busque mucho sobre estas funcionesno teniendo existo... muy agradecido...

Re: FTP ???

Posted: Wed Jun 15, 2011 12:41 pm
by MarioG
Hola;
Estoy interesado en usar estas funciones, y mas presisamente en esta:
DLL32 FUNCTION FTPGETFILE( hConnect AS LONG, cRemoteFile AS LPSTR, cNewFile AS LPSTR, nFailIfExists AS LONG, nFlagsAndAttribs AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS BOOL;
PASCAL FROM "FtpGetFileA" LIB "wininet.dll"

Me podrían decir el valor de los siguientes parámetros, o como los obtengo?
cRemoteFile: debe ser la dirección completa del FTP?
cNewFile: se puede incluir el camino de la carpeta destino?
hConnect: si me conecto con TFtpFile(), obtengo tal valor de la clase?
nFaillExists: ?
nFlagsAndAttribs: ?
nFlags: ?
nContext: ?

muchas gracias

Re: FTP ???

Posted: Thu Jun 30, 2011 12:57 pm
by Mayor_Valenzuela
Este ejemplo lo puedes usar para entender como funciona... debe crear o tener una cuenta FTP para poder conectarte...

Code: Select all

#include "FiveWin.ch"
#include "TsButton.ch"
#define FILE_ATTRIBUTE_READONLY 1
#define FILE_ATTRIBUTE_HIDDEN 2
#define FILE_ATTRIBUTE_SYSTEM 4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE 32
#define FILE_ATTRIBUTE_NORMAL 128
#define FILE_ATTRIBUTE_TEMPORARY 256
#define INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
#define INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
#define INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS
#define INTERNET_INVALID_PORT_NUMBER    0       // use the protocol-specific default
#define INTERNET_DEFAULT_FTP_PORT       21      // default for FTP servers
#define INTERNET_DEFAULT_GOPHER_PORT    70      //    "     " gopher "
#define INTERNET_DEFAULT_HTTP_PORT      80      //    "     " HTTP   "
#define INTERNET_DEFAULT_HTTPS_PORT     443     //    "     " HTTPS  "
#define INTERNET_DEFAULT_SOCKS_PORT     1080    // default for SOCKS firewall servers.
#define INTERNET_SERVICE_FTP     1
#define INTERNET_SERVICE_GOPHER  2
#define INTERNET_SERVICE_HTTP    3
#define INTERNET_FLAG_TRANSFER_ASCII  1
#define INTERNET_FLAG_TRANSFER_BINARY 2
Static oWnd
Static hBorland, User, hParaBNt
*..............................................................................................................................*
Function Main()
Local oDlg, oBar, oBmp, oIco, lOk, Local1:=GetWinDir(), oFont[1], FileName, oItem, oBsh, oTxt
Public Ubica:=CurDrive()+":\"+CurDir()
Public nClr:=aRGB( GetSysColor(15) ), CLR_SYSTEM

CLR_SYSTEM := RGB( nClr[1],nClr[2],nClr[3] )
hBorland:=LoadLibrary( ".\System\bwcc32.dll" )
Set Date British
Set Century On
Set _3DLOOK On

DEFINE FONT oFont[1] NAME "Arial" WEIGHT 12

DEFINE DIALOG oDlg RESOURCE "DIALOG_MAIN" ICON oIco COLOR CLR_BLACK, CLR_WHITE BRUSH oBsh

 REDEFINE SBUTTON ID 101 NAME "RUN2" TEXT POSITION ON_BOTTOM OF oDlg ACTION ( GetFtp( oDlg ) ) BORDER CANCEL
 REDEFINE SAY oTxt ID 102 OF oDlg

ACTIVATE DIALOG oDlg CENTERED;
         VALID ( If( !GetKeyState( VK_ESCAPE ),  .T.,  .F. ) )

Return ( Nil )
*..............................................................................................................................*
Static Function GetFtp(oDlg)
Local oInternet, usuario:="administrador@banks.com", password:="xxxxxx"  // estas se reemplazan con tu usuario y password
Local oFtp, lExito, False:=.F., True:=.T.
Local cLocalFile:="C:\Link\Mproduct.zip", cRemoteFile:="/LTO/mproduct.zip"

 oInternet := TInternet():New()
 oFTP      := TFTP():New( "167.119.250.194", oInternet, usuario, password )
 hLib = LOADLIBRARY( "wininet.dll" )
 hInternet = INETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
 hConnect = INETCONNECT( hInternet, "167.119.250.194",  21, usuario, password,1, 0, 0 )
 IF hConnect = 0
   MsgAlert("Fallo la conección con el Servidor!" + chr(13)+"Intente nuevamente.")
   FREELIBRARY( hLib )
   INETCLOSEHANDLE( hConnect )
   INETCLOSEHANDLE( hInternet )
   FREELIBRARY( hLib )
   Return ( Nil )
 Else
     MsgRun( "Descargando archivo local MALL PLAZA, favor esperar.","Conectando")
   lExito := FTPGETFILE( hConnect, cRemoteFile, cLocalFile, 0, FILE_ATTRIBUTE_ARCHIVE, 0, 0)
   If !lExito
     MsgAlert( "No se pudo realizar la descarga desde el servidor.", "Error!")
     FREELIBRARY( hLib )
     INETCLOSEHANDLE( hConnect )
     INETCLOSEHANDLE( hInternet )
     FREELIBRARY( hLib )
         MsgRun("")
     Else
         aFiles := hb_GetFilesInZip(cLocalFile)
         hb_unzipfile(cLocalFile,,.T.,,"C:\", aFiles, NIL)
         While .T.
           If ( CopyFile("c:\Link\Fab\LTO\Mproduct.dat", "c:\Ventas\Bases\Mproduct.dat") = .F. )
               If ( MsgYesNo("Es necesario que salga del sistema de ventas para realizar este proceso. Desea reintentar?", "Error") )
                     Loop
                 Else
                        Exit
               EndIf
             Else
                 Exit
           EndIf
         End While
   EndIf
     oDlg:End()
     MsgRun("")
  EndIf

Return ( Nil )
*...............................................................................................................................*
DLL32 FUNCTION INETOPEN( cAgent AS LPSTR, nAccessType AS DWORD, cProxyName AS LPSTR, cProxyBypass AS LPSTR, nFlags AS DWORD ) AS LONG;
PASCAL FROM "InternetOpenA" LIB "wininet.dll"

DLL32 FUNCTION INETCLOSEHANDLE( hInternet AS LONG ) AS BOOL;
PASCAL FROM "InternetCloseHandle" LIB "wininet.dll"

DLL32 FUNCTION INETCONNECT( hInternet AS LONG, cServerName AS LPSTR, nServerPort AS LONG, cUserName AS LPSTR, cPassword AS LPSTR, nService AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS LONG;
PASCAL FROM "InternetConnectA" LIB "wininet.dll"

DLL32 FUNCTION FTPGETFILE( hConnect AS LONG, cRemoteFile AS LPSTR, cNewFile AS LPSTR, nFailIfExists AS LONG, nFlagsAndAttribs AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS BOOL;
PASCAL FROM "FtpGetFileA" LIB "wininet.dll"

DLL32 FUNCTION FTPPUTFILE( hConnect AS LONG, cLocalFile AS LPSTR, cNewRemoteFile AS LPSTR, nFlags AS DWORD, @nContext AS PTR ) AS BOOL;
PASCAL FROM "FtpPutFileA" LIB "wininet.dll"

DLL FUNCTION COPYFILE( cExistingFileName AS LPSTR, cNewFileName AS LPSTR, lFailIfExists AS LONG ) AS BOOL;
    PASCAL FROM "CopyFileA" LIB "kernel32.dll"
*...............................................................................................................................*



Re: FTP ???

Posted: Thu Jun 30, 2011 1:17 pm
by jbrita
Mario,
tienes un correo para contactarte

Saludos

Re: FTP ???

Posted: Thu Jun 30, 2011 3:05 pm
by QAZWSX2K
sobre FTP les cuento que todas esas funciones, generan un atchivo log, de nombre ftp.log, ftp0.log, ftp1.log...ftp2222.log cada vez que se ejecutan y si ven ese archivo log aparece hasta la clave en cristiano, cosa entonces que cualquier puede despues manualmente a nuestro ftp y por supuesto hacer y deshacer por ahi, entonces mi preguntas es..

¿existe alguna variable dentro de esta clase para que no genere el archivo log?

Re: FTP ???

Posted: Thu Jun 30, 2011 3:10 pm
by MarioG
Mayor;
muchas gracias, lo probaré

JB mi correo es: mario.r.gonzalez(a)gmail.com

Re: FTP ???

Posted: Mon Jul 04, 2011 8:58 pm
by Mayor_Valenzuela
Mi correo...

mayor_valenzuela@hotmail.com

Espero haber aportado en algo, y ante cualquier duda n duden en contactarme por correo..