by Elias Torres » Fri Nov 17, 2006 1:15 pm
Antonio el codigo es el siguiente...
#include "Fwce.ch"
//
// File attributes
//
#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
//
// access types for InternetOpen()
//
#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
//
// manifests
//
#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.
//
// service types for InternetConnect()
//
#define INTERNET_SERVICE_FTP 1
#define INTERNET_SERVICE_GOPHER 2
#define INTERNET_SERVICE_HTTP 3
//
// flags for FTP
//
#define INTERNET_FLAG_TRANSFER_ASCII 1
#define INTERNET_FLAG_TRANSFER_BINARY 2
FUNCTION MAIN()
LOCAL oWnd
PUBLIC server:="ftp://ipftp"+space(15)
PUBLIC user:="usuario"+space(15)
PUBLIC pass:="pass"+space(15)
PUBLIC loc_archivo:=curdir()+"\users.bmp"+space(15)
PUBLIC rem_archivo:="users.bmp"+space(40)
PUBLIC lSobreescribir:=.T.
PUBLIC lBinary:=.T.
DEFINE WINDOW oWND TITLE "Prueba FTP"
#DEFINE margen_derecho 5
#DEFINE largo_say 100
#DEFINE largo_get 130
#DEFINE ancho 20
#DEFINE separacion_entre_lineas ancho+10
** SERVIDOR:
#DEFINE oSay1 oWND:aControls[1]
@10,margen_derecho SAY "Servidor: " SIZE largo_say, ancho PIXEL OF oWND
@ oSay1:ntop, oSay1:nRight+1 GET server SIZE largo_get, ancho PIXEL OF oWnd
** USER:
#DEFINE oSay2 oWnd:aControls[3]
@ oSay1:nTop+separacion_entre_lineas, margen_derecho SAY "User:" SIZE largo_say, ancho PIXEL OF oWnd
@ oSay2:nTop, oSay2:nRight+1 GET user SIZE largo_get,ancho PIXEL OF oWnd
** PASS:
#DEFINE oSay3 oWnd:aControls[5]
@ oSay2:nTop+separacion_entre_lineas, margen_derecho SAY "Password:" SIZE largo_say, ancho PIXEL OF oWnd
@ oSay3:nTop, oSay3:nRight+1 GET pass SIZE largo_get,ancho PIXEL OF oWnd
* ARCHIVO LOCAL:
#DEFINE oSay4 oWnd:aControls[7]
@ oSay3:nTop+separacion_entre_lineas, margen_derecho SAY "Archivo local:" SIZE largo_say, ancho PIXEL OF oWnd
@ oSay4:nTop, oSay4:nRight+1 GET loc_archivo SIZE largo_get,ancho PIXEL OF oWnd
* ARCHIVO REMOTO:
#DEFINE oSay5 oWnd:aControls[9]
@ oSay4:nTop+separacion_entre_lineas, margen_derecho SAY "Archivo Remoto:" SIZE largo_say, ancho PIXEL OF oWnd
@ oSay5:nTop, oSay5:nRight+1 GET rem_archivo SIZE largo_get,ancho PIXEL OF oWnd
* ENVIAR
#DEFINE oButton1 oWnd:aControls[11]
@ oSay5:nTop+separacion_entre_lineas, margen_derecho+10 BUTTON "Enviar" SIZE 50, ancho PIXEL ACTION msginfo(enviar()) OF oWnd
* TRAER
#DEFINE oButton2 oWnd:aControls[12]
@ oButton1:nTop, oButton1:nRight+20 BUTTON "Traer" SIZE 50, ancho PIXEL ACTION msginfo(traer()) OF oWnd
* SOBREESCRIBIR
#DEFINE oChk1 oWnd:aControls[13]
@ oButton1:nTop+separacion_entre_lineas, margen_derecho CHECKBOX lSobreescribir PROMPT "Sobreescribir" SIZE 150, ancho PIXEL OF oWnd
* BINARY
#DEFINE oChk2 oWnd:aControls[14]
@ oChk1:nTop+separacion_entre_lineas, margen_derecho CHECKBOX lBinary PROMPT "Transferencia Binaria" SIZE 150, ancho PIXEL OF oWnd
ACTIVATE WINDOW oWND
RETURN NIL
FUNCTION Enviar()
LOCAL nRet
LOCAL hInternet, hConnect
hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
hConnect = INTERNETCONNECT(hInternet, rtrim(server), INTERNET_INVALID_PORT_NUMBER, rtrim(user), rtrim(pass), INTERNET_SERVICE_FTP, 0, 0 )
IF FTPPUTFILE( hConnect, rtrim(loc_archivo), rtrim(rem_archivo),iif(lBinary,INTERNET_FLAG_TRANSFER_BINARY,INTERNET_FLAG_TRANSFER_ASCII), 0 )
nRet:=0
ELSE
nRet:=GetLAstError()
ENDIF
INTERNETCLOSEHANDLE( hConnect )
INTERNETCLOSEHANDLE( hInternet )
RETURN nRet
FUNCTION Traer()
LOCAL nRet
LOCAL hInternet, hConnect
hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
hConnect = INTERNETCONNECT(hInternet, rtrim(server), INTERNET_INVALID_PORT_NUMBER, rtrim(user), rtrim(pass), INTERNET_SERVICE_FTP, 0, 0 )
IF FTPGETFILE( hConnect, rtrim(rem_archivo), rtrim(loc_archivo), IIF( lSobreescribir,0,1), FILE_ATTRIBUTE_ARCHIVE, 0, 0 )
nRet:=0
ELSE
nRet:=GetLAstError()
ENDIF
INTERNETCLOSEHANDLE( hConnect )
INTERNETCLOSEHANDLE( hInternet )
RETURN nRet
#pragma BEGINDUMP
#include "windows.h"
#include "wininet.h"
#include "hbapi.h"
LPWSTR AnsiToWide( LPSTR );
HB_FUNC( INTERNETOPEN )
{
LPWSTR cAgent = AnsiToWide( hb_parc( 1 ) );
LPWSTR cProxyName = AnsiToWide( hb_parc( 3 ) );
LPWSTR cProxyBypass = AnsiToWide( hb_parc( 4 ) );
HINTERNET hInternet = InternetOpen( cAgent, hb_parnl( 2 ), cProxyName, cProxyBypass, hb_parnl( 5 ) );
hb_xfree( cAgent );
hb_xfree( cProxyName );
hb_xfree( cProxyBypass );
hb_retnl( ( LONG ) hInternet );
}
HB_FUNC( INTERNETCLOSEHANDLE )
{
hb_retl( InternetCloseHandle( ( HINTERNET ) hb_parnl( 1 ) ) );
}
HB_FUNC( INTERNETCONNECT )
{
LPWSTR cServerName = AnsiToWide( hb_parc( 2 ) );
LPWSTR cUserName = AnsiToWide( hb_parc( 4 ) );
LPWSTR cPassword = AnsiToWide( hb_parc( 5 ) );
HINTERNET hInternet = InternetConnect( ( HINTERNET ) hb_parnl( 1 ), cServerName, ( INTERNET_PORT ) hb_parnl( 3 ), cUserName, cPassword, hb_parnl( 6 ), hb_parnl( 7 ), hb_parnl( 8 ) );
hb_xfree( cServerName );
hb_xfree( cUserName );
hb_xfree( cPassword );
hb_retnl( ( LONG ) hInternet );
}
HB_FUNC( FTPGETFILE )
{
LPWSTR cRemoteFile = AnsiToWide( hb_parc( 2 ) );
LPWSTR cNewFile = AnsiToWide( hb_parc( 3 ) );
hb_retl( FtpGetFile( ( HINTERNET ) hb_parnl( 1 ), cRemoteFile, cNewFile, hb_parl( 4 ), hb_parnl( 5 ), hb_parnl( 6 ), hb_parnl( 7 ) ) );
hb_xfree( cRemoteFile );
hb_xfree( cNewFile );
}
HB_FUNC( FTPPUTFILE )
{
LPWSTR cLocalFile = AnsiToWide( hb_parc( 2 ) );
LPWSTR cNewRemoteFile = AnsiToWide( hb_parc( 3 ) );
hb_retl( FtpPutFile( ( HINTERNET ) hb_parnl( 1 ), cLocalFile, cNewRemoteFile, hb_parnl( 4 ), hb_parnl( 5 ) ) );
hb_xfree( cLocalFile );
hb_xfree( cNewRemoteFile );
}
#pragma ENDDUMP
Saludos...
Elías Torres.