tftp class
- Antonio Linares
- Site Admin
- Posts: 42529
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 77 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42529
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 77 times
- Contact:
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
Vilian
This is a working sample
My app uses ftp very intensively and it works OK.
FUNCTION RLOGTRN(TPAR,TFICLOG) // Récupérer FICHIERS LOGTRN QUI INDIQUENT CE QU'IL Y A à TéLécharger
LOCAL hInternet,DFIC,DFICL,DFICR, ;
I := 0, ;
J := 0, ;
DSITE := SPACE(100), ;
DUSER := SPACE(30), ;
DPASS := SPACE(10), ;
DDIR := SPACE(100), ;
HCON
local oInternet
local oFTP
local aFiles
DSITE := ALLTRIM(TPAR[08])
DUSER := ALLTRIM(TPAR[09])
DPASS := ALLTRIM(TPAR[10])
DDIR := ALLTRIM(TPAR[11])
oInternet := TInternet():New()
oFTP := TFTP():New( DSITE, oInternet, DUSER, DPASS )
if ! Empty( oFTP:hFTP )
aFiles = oFTP:Directory(DDIR)
endif
if ! Empty( oFTP:hFTP )
aFiles = oFTP:Directory( ddir + "LOGTRN*.*" )
endif
oInternet:End()
hInternet := InternetOpen( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 ) // pocket connexion gprs
IF hINTERNET = 0
MSGINFO("ERREUR CONNEXION INTERNET")
RETURN NIL
ENDIF
hCon = INTERNETCONNECT( hInternet, DSITE,INTERNET_INVALID_PORT_NUMBER, DUSER, DPASS, INTERNET_SERVICE_FTP, 0,0 )
IF HCON = 0
MSGSTOP("Trop de connexion en cours, essayez plus tard !")
RETURN NIL
ENDIF
J := 0
FOR I = 1 TO LEN(AFILES)
IFILE := AFILES[I]
DFIC := ALLTRIM(IFILE[1])
IF SUBS(DFIC,1,1) = "." .OR. ASC(SUBS(DFIC,1,1)) = 0
ELSE
DFICL := CurDir() + "\ENTRANT\" + alltrim(dfic) // LOCAL FILE
DFICR := ALLTRIM(DDIR ) + alltrim(dfic) // REMOTE FILE
AADD(TFICLOG,DFIC) // STOCKER NOM FICHIER DANS TABLEAU POUR EFFACER APRES SYNCRO
FTPGETFILE( hCon, DFICR , DFICL, 0,FILE_ATTRIBUTE_ARCHIVE, 0, 0 )
ENDIF
NEXT
INTERNETCLOSEHANDLE( hCon )
INTERNETCLOSEHANDLE( hInternet )
return nil
PS : if you need other samples, please let me know
HTH
Richard
Ps : For ANTONIO
Enrico's sample is excellent but it will not work together with tftp class (using the same function names)
This is a working sample

My app uses ftp very intensively and it works OK.
FUNCTION RLOGTRN(TPAR,TFICLOG) // Récupérer FICHIERS LOGTRN QUI INDIQUENT CE QU'IL Y A à TéLécharger
LOCAL hInternet,DFIC,DFICL,DFICR, ;
I := 0, ;
J := 0, ;
DSITE := SPACE(100), ;
DUSER := SPACE(30), ;
DPASS := SPACE(10), ;
DDIR := SPACE(100), ;
HCON
local oInternet
local oFTP
local aFiles
DSITE := ALLTRIM(TPAR[08])
DUSER := ALLTRIM(TPAR[09])
DPASS := ALLTRIM(TPAR[10])
DDIR := ALLTRIM(TPAR[11])
oInternet := TInternet():New()
oFTP := TFTP():New( DSITE, oInternet, DUSER, DPASS )
if ! Empty( oFTP:hFTP )
aFiles = oFTP:Directory(DDIR)
endif
if ! Empty( oFTP:hFTP )
aFiles = oFTP:Directory( ddir + "LOGTRN*.*" )
endif
oInternet:End()
hInternet := InternetOpen( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 ) // pocket connexion gprs
IF hINTERNET = 0
MSGINFO("ERREUR CONNEXION INTERNET")
RETURN NIL
ENDIF
hCon = INTERNETCONNECT( hInternet, DSITE,INTERNET_INVALID_PORT_NUMBER, DUSER, DPASS, INTERNET_SERVICE_FTP, 0,0 )
IF HCON = 0
MSGSTOP("Trop de connexion en cours, essayez plus tard !")
RETURN NIL
ENDIF
J := 0
FOR I = 1 TO LEN(AFILES)
IFILE := AFILES[I]
DFIC := ALLTRIM(IFILE[1])
IF SUBS(DFIC,1,1) = "." .OR. ASC(SUBS(DFIC,1,1)) = 0
ELSE
DFICL := CurDir() + "\ENTRANT\" + alltrim(dfic) // LOCAL FILE
DFICR := ALLTRIM(DDIR ) + alltrim(dfic) // REMOTE FILE
AADD(TFICLOG,DFIC) // STOCKER NOM FICHIER DANS TABLEAU POUR EFFACER APRES SYNCRO
FTPGETFILE( hCon, DFICR , DFICL, 0,FILE_ATTRIBUTE_ARCHIVE, 0, 0 )
ENDIF
NEXT
INTERNETCLOSEHANDLE( hCon )
INTERNETCLOSEHANDLE( hInternet )
return nil
PS : if you need other samples, please let me know
HTH
Richard
Ps : For ANTONIO
Enrico's sample is excellent but it will not work together with tftp class (using the same function names)
- Antonio Linares
- Site Admin
- Posts: 42529
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 77 times
- Contact:
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
Here you have it
FUNCTION EINTERN(TPAR,TFIC,LOGOUT) // ENVOI SYNCRO PAR INTERNET DU POCKET VERS LE PC DOSSIER CURDIR() + "\SORTANT\*.* a syncroniser vers dest dans aval (tpar))
LOCAL hInternet,DFICL,DFICR, ;
HCON := {}, ;
I := 0, ;
CTR := 0, ;
DSITE := SPACE(100), ;
DUSER := SPACE(30), ;
DPASS := SPACE(10), ;
DDIR := SPACE(100), ;
HCON1
// TPAR[01] := PKID->IDCBATIPK
// TPAR[02] := PKID->PKPC
// TPAR[03] := PKID->PKPCSITE
// TPAR[04] := PKID->PKPCUSER
// TPAR[05] := PKID->PKPCPASS
// TPAR[06] := PKID->PKPCDIR
// TPAR[07] := PKID->PCPK
// TPAR[08] := PKID->PCPKSITE
// TPAR[09] := PKID->PCPKUSER
// TPAR[10] := PKID->PCPKPASS
// TPAR[11] := PKID->PCPKDIR
DSITE := ALLTRIM(TPAR[03])
DUSER := ALLTRIM(TPAR[04])
DPASS := ALLTRIM(TPAR[05])
DDIR := ALLTRIM(TPAR[06])
hInternet := InternetOpen( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 ) // pocket connexion gprs
hCon1 = INTERNETCONNECT( hInternet, DSITE,0, DUSER, DPASS, INTERNET_SERVICE_FTP, 0,0 )
IF HCON1 = 0
MSGINFO("ERREUR Création CONNEXION FTP ... Abandon transmission ")
RETURN .F.
ENDIF
FOR I = 1 TO LEN(TFIC)
DFICL := CurDir() + "\SORTANT\" + ALLTRIM(TFIC[I]) // Fichier local
DFICR := ALLTRIM(DDIR) + ALLTRIM(TFIC[I]) // FICHIER REMOTE
IF FTPPUTFILE( hCon1, DFICL, DFICR, 0, 0 )
AADD(LOGOUT,TFIC[I])
ENDIF
NEXT
INTERNETCLOSEHANDLE( hCon1 )
INTERNETCLOSEHANDLE( hInternet )
RETURN .T.
Regards
Richard
FUNCTION EINTERN(TPAR,TFIC,LOGOUT) // ENVOI SYNCRO PAR INTERNET DU POCKET VERS LE PC DOSSIER CURDIR() + "\SORTANT\*.* a syncroniser vers dest dans aval (tpar))
LOCAL hInternet,DFICL,DFICR, ;
HCON := {}, ;
I := 0, ;
CTR := 0, ;
DSITE := SPACE(100), ;
DUSER := SPACE(30), ;
DPASS := SPACE(10), ;
DDIR := SPACE(100), ;
HCON1
// TPAR[01] := PKID->IDCBATIPK
// TPAR[02] := PKID->PKPC
// TPAR[03] := PKID->PKPCSITE
// TPAR[04] := PKID->PKPCUSER
// TPAR[05] := PKID->PKPCPASS
// TPAR[06] := PKID->PKPCDIR
// TPAR[07] := PKID->PCPK
// TPAR[08] := PKID->PCPKSITE
// TPAR[09] := PKID->PCPKUSER
// TPAR[10] := PKID->PCPKPASS
// TPAR[11] := PKID->PCPKDIR
DSITE := ALLTRIM(TPAR[03])
DUSER := ALLTRIM(TPAR[04])
DPASS := ALLTRIM(TPAR[05])
DDIR := ALLTRIM(TPAR[06])
hInternet := InternetOpen( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 ) // pocket connexion gprs
hCon1 = INTERNETCONNECT( hInternet, DSITE,0, DUSER, DPASS, INTERNET_SERVICE_FTP, 0,0 )
IF HCON1 = 0
MSGINFO("ERREUR Création CONNEXION FTP ... Abandon transmission ")
RETURN .F.
ENDIF
FOR I = 1 TO LEN(TFIC)
DFICL := CurDir() + "\SORTANT\" + ALLTRIM(TFIC[I]) // Fichier local
DFICR := ALLTRIM(DDIR) + ALLTRIM(TFIC[I]) // FICHIER REMOTE
IF FTPPUTFILE( hCon1, DFICL, DFICR, 0, 0 )
AADD(LOGOUT,TFIC[I])
ENDIF
NEXT
INTERNETCLOSEHANDLE( hCon1 )
INTERNETCLOSEHANDLE( hInternet )
RETURN .T.
Regards
Richard
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
You may need this also
#include "C:\FWPPC\INCLUDE\FWCE.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
//
// 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
#include "C:\FWPPC\INCLUDE\FWCE.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
//
// 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
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
Vilian
Make sure you have the correct access on the server where you want to put the file and that there is no "Disk Quota" or something similar.
The code i sent you works OK.
We have several customers that use it, they send maintenance data from their pocket (via our application) to our server and receive back some other data. FWPPC works OK on this.
The only problem i can not handle properly at the moment is closing the gprs connexion (when used) "Always" . From time to time it remains open. I am working on it.
Hth
PS : What type of server are you uisng ? Linux ? Plex system ?
If using a plex system, make sure you address the main domain "userid and password", if not create sub domains
Richard
Make sure you have the correct access on the server where you want to put the file and that there is no "Disk Quota" or something similar.
The code i sent you works OK.
We have several customers that use it, they send maintenance data from their pocket (via our application) to our server and receive back some other data. FWPPC works OK on this.
The only problem i can not handle properly at the moment is closing the gprs connexion (when used) "Always" . From time to time it remains open. I am working on it.
Hth
PS : What type of server are you uisng ? Linux ? Plex system ?
If using a plex system, make sure you address the main domain "userid and password", if not create sub domains
Richard
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
Hello Vilian
Sorry i was on vacation for the last week. Needed some sunshine...
Back to FTP,
If you are connected to the PC (window 2003 server) from your pocket, then you are on a "local" connexion, in this case, ftp wil not work. You will need just a copy file to copy from the pocket to windows 2003 server. This is what we do when the pocket is local (never use ftp in local mode, we use cecopy instead to copy from the PC to the pocket)
Just make sure your pocket is "not connected" to the pc when you want to use ftp.
HTH
Richard
Sorry i was on vacation for the last week. Needed some sunshine...
Back to FTP,
If you are connected to the PC (window 2003 server) from your pocket, then you are on a "local" connexion, in this case, ftp wil not work. You will need just a copy file to copy from the pocket to windows 2003 server. This is what we do when the pocket is local (never use ftp in local mode, we use cecopy instead to copy from the PC to the pocket)
Just make sure your pocket is "not connected" to the pc when you want to use ftp.
HTH
Richard