Necesito conectarme a una FTP
- Mayor_Valenzuela
- Posts: 62
- Joined: Tue Jul 08, 2008 4:27 pm
- Location: Santiago, Chile
Necesito conectarme a una FTP
Bueno hace mucho tiempo que no visito este foro y debido a nuevos requerimientos me veo en la necesidad de pedir ayuda a los que mas saben, mi cuento es: Tengo 11 locales de ventas, llege hace muy poco a trabajar a este lugar, usan un programa clipper muy antiguo y bastante cuadrado, el tema es con la lista de precios por cada uno de estos locales, estas cambian varias veces por semana, y todos _ los realizo via Mail, ahora quiero que nuan pequeña aplicacion se conecte al servidor y baje el archivo sin la intervencion del usuario ya que varias veces e tenido problemas con estos. No entiendo mucho de FTP y si es que puedo realizar esta tarea, es como sincronizar y actualizar los datos de forma segura. Espero puedan ayudarme con el tema. Gracias
Mario Valenzuela M.
Santiago, Chile.
Santiago, Chile.
Re: Necesito conectarme a una FTP
Hola Mayor
Puedes ver en el codigo mas abajo como conectarse y bajar archivo de un FTP server.
Saludos
George
Puedes ver en el codigo mas abajo como conectarse y bajar archivo de un FTP server.
Code: Select all
// 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
//=======================================================================================================================
// En la parte del programa para conexion al FTP debe ir lo siguiente
// Crear oFtp Objeto
oInternet := TInternet():New()
oFTP := TFTP():New( "IP Address", oInternet, "UserID", "Password" )
// Cargar la libreria que contiene las funciones de internet
hLib = LOADLIBRARY( "wininet.dll" )
// Verifica Internet y conexion al mismo
hInternet = INETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
hConnect = INETCONNECT( hInternet, "IP Address", 21, "UserID", "Password",1, 0, 0 )
// En caso de que falle la conexion
IF hConnect = 0
MsgAlert("Connection to server failed!" + chr(13)+;
"Please try later.")
//OpenFiles()
FREELIBRARY( hLib )
INETCLOSEHANDLE( hConnect )
INETCLOSEHANDLE( hInternet )
FREELIBRARY( hLib )
oDlg:end()
RETURN FALSE
ENDIF
// Si la conexion es exitosa proceder a bajar el file del FTP
lGet := FTPGETFILE( hConnect, cRemoteFile, cLocalFile, 0, FILE_ATTRIBUTE_ARCHIVE, 0, 0)
// Verifica si se ejecuto correctamente el "download" desde el FTP
IF lGet
MsgInfo("File downloaded successfully..")
ELSE
MsgAlert( "The file could not be downloaded from remote server", "Error!")
FREELIBRARY( hLib )
INETCLOSEHANDLE( hConnect )
INETCLOSEHANDLE( hInternet )
FREELIBRARY( hLib )
oDlg:end()
RETURN FALSE
ENDIF
// Nota: Si quieres enviar algun file al FTP server entonces debes usar la funcion FTPPUTFILE
//=======================================================================================================================
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"
George
- Mayor_Valenzuela
- Posts: 62
- Joined: Tue Jul 08, 2008 4:27 pm
- Location: Santiago, Chile
Re: Necesito conectarme a una FTP
Muchas gracias George... pude conectarme al servidor, pero no me imagino como debo enviar en la variable cNewRemoteFile, ya que yo lo asigne de la siguiente forma "L33\mproduct.dbf" no se si la sintaxis esta corecta ya que el archivo lo subo a un directorio previamente ceado en el servidor.. puede que le parametro en realidad sea "\L33\mproduct.dbf" sorry por mi ignorancia...
Mario Valenzuela M.
Santiago, Chile.
Santiago, Chile.
Re: Necesito conectarme a una FTP
Esta es la sintaxis usada:
// FTPPUTFILE( hConnect, "local file name", "remote file name", 0, 0 )
/* Ejemplo */
Saludos
George
// FTPPUTFILE( hConnect, "local file name", "remote file name", 0, 0 )
/* Ejemplo */
Code: Select all
FTPPUTFILE( hConnect, "c:\temp_dir\ftp1.zip", "/anon_ftp/TEST/FTP01.ZIP", 0, 0 )
Saludos
George
- Mayor_Valenzuela
- Posts: 62
- Joined: Tue Jul 08, 2008 4:27 pm
- Location: Santiago, Chile
Re: Necesito conectarme a una FTP
Muchas gracias por la ayuda...
Mario Valenzuela M.
Santiago, Chile.
Santiago, Chile.