Discussion:
File Transfer without using FTP Protocol in Foxpro
(too old to reply)
Heberto Villavicencio
2003-08-02 00:53:25 UTC
Permalink
**
** Upload files to ftp server
**

#DEFINE GENERIC_READ 2147483648 && &H80000000
#DEFINE GENERIC_WRITE 1073741824 && &H40000000

PUBLIC hOpen, hFtpSession
DECLARE INTEGER InternetOpen IN wininet.dll;
STRING sAgent,;
INTEGER lAccessType,;
STRING sProxyName,;
STRING sProxyBypass,;
STRING lFlags

DECLARE INTEGER InternetCloseHandle IN wininet.dll;
INTEGER hInet

DECLARE INTEGER InternetConnect IN wininet.dll;
INTEGER hInternetSession,;
STRING sServerName,;
INTEGER nServerPort,;
STRING sUsername,;
STRING sPassword,;
INTEGER lService,;
INTEGER lFlags,;
INTEGER lContext

DECLARE INTEGER FtpOpenFile IN wininet.dll;
INTEGER hFtpSession,;
STRING sFileName,;
INTEGER lAccess,;
INTEGER lFlags,;
INTEGER lContext

DECLARE INTEGER InternetWriteFile IN wininet.dll;
INTEGER hFile,;
STRING @ sBuffer,;
INTEGER lNumBytesToWrite,;
INTEGER @ dwNumberOfBytesWritten

IF connect2ftp ("ftp.yourftpserver.com", "user", "password")
lcSourcePath = "C:\upload\" && local folder
lcTargetPath = "/www/" && remote folder (ftp server)

lnFiles = ADIR (arr, lcSourcePath + "*.*")

FOR lnCnt=1 TO lnFiles
lcSource = lcSourcePath + LOWER (arr [lnCnt, 1])
lcTarget = lcTargetPath + LOWER (arr [lnCnt, 1])
? lcSource + " -> " + lcTarget
?? local2ftp (hFtpSession, lcSource, lcTarget)
ENDFOR

= InternetCloseHandle (hFtpSession)
= InternetCloseHandle (hOpen)
ENDIF

FUNCTION connect2ftp (strHost, strUser, strPwd)
** Abrimos el acceso.
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)

IF hOpen = 0
? "No tiene acceso a WinInet.Dll"
RETURN .F.
ENDIF

** Connect to FTP.
hFtpSession = InternetConnect (hOpen, strHost, 0, strUser, strPwd, 1, 0,
0)

IF hFtpSession = 0
** Close
= InternetCloseHandle (hOpen)
? "FTP " + strHost + " not ready"
RETURN .F.
ELSE
? "Conectado a " + strHost + " como: [" + strUser + ", *****]"
ENDIF
RETURN .T.


**--------------------------------------------
** Copia del/los archivos
**--------------------------------------------
FUNCTION local2ftp (hConnect, lcSource, lcTarget)
** Upload local file to ftp server
hSource = FOPEN (lcSource)
IF (hSource = -1)
RETURN -1
ENDIF

** New file in ftp server
hTarget = FtpOpenFile(hConnect, lcTarget, GENERIC_WRITE, 2, 0)
IF hTarget = 0
= FCLOSE (hSource)
RETURN -2
ENDIF
lnBytesWritten = 0
lnChunkSize = 512 && 128, 512
DO WHILE Not FEOF(hSource)
lcBuffer = FREAD (hSource, lnChunkSize)
lnLength = Len(lcBuffer)
IF lnLength > 0
IF InternetWriteFile (hTarget, @lcBuffer, lnLength, @lnLength) =
1
lnBytesWritten = lnBytesWritten + lnLength
? lnBytesWritten
** Show Progress
ELSE
EXIT
ENDIF
ELSE
EXIT
ENDIF
ENDDO

= InternetCloseHandle (hTarget)
= FCLOSE (hSource)

RETURN lnBytesWritten
Can someone give me some sample code has to how to initate
a file transfer from within Foxpro.
I have an import and export routine that sure could use
such a thing
Thanks
Glen
-----Original Message-----
We are distributing a foxpro application that uses
Microsoft FTP to send files back to the server. Malicious
users dumped files on our Win 2K server when the ftp
service was perpetually enabled. So, I have a a few
1. Is it possible to send files to our server from within
a (remotely running) foxpro application without using
ftp,
say using http instead of ftp.
2. Is there a way that the ftp service can be started and
stopped on the Win2k Server from within a foxpro
application running remotely?
3. Are there any other ways of sending small files to our
server from a remotely running foxpro application?
Thank you.
Humty
.
Glen Wagner
2003-08-02 01:43:18 UTC
Permalink
Heberto
WOW thanks so much
Glen
-----Original Message-----
**
** Upload files to ftp server
**
#DEFINE GENERIC_READ 2147483648 && &H80000000
#DEFINE GENERIC_WRITE 1073741824 && &H40000000
PUBLIC hOpen, hFtpSession
DECLARE INTEGER InternetOpen IN wininet.dll;
STRING sAgent,;
INTEGER lAccessType,;
STRING sProxyName,;
STRING sProxyBypass,;
STRING lFlags
DECLARE INTEGER InternetCloseHandle IN wininet.dll;
INTEGER hInet
DECLARE INTEGER InternetConnect IN wininet.dll;
INTEGER hInternetSession,;
STRING sServerName,;
INTEGER nServerPort,;
STRING sUsername,;
STRING sPassword,;
INTEGER lService,;
INTEGER lFlags,;
INTEGER lContext
DECLARE INTEGER FtpOpenFile IN wininet.dll;
INTEGER hFtpSession,;
STRING sFileName,;
INTEGER lAccess,;
INTEGER lFlags,;
INTEGER lContext
DECLARE INTEGER InternetWriteFile IN wininet.dll;
INTEGER hFile,;
INTEGER lNumBytesToWrite,;
IF connect2ftp
("ftp.yourftpserver.com", "user", "password")
lcSourcePath = "C:\upload\" && local folder
lcTargetPath = "/www/" && remote folder (ftp
server)
lnFiles = ADIR (arr, lcSourcePath + "*.*")
FOR lnCnt=1 TO lnFiles
lcSource = lcSourcePath + LOWER (arr [lnCnt, 1])
lcTarget = lcTargetPath + LOWER (arr [lnCnt, 1])
? lcSource + " -> " + lcTarget
?? local2ftp (hFtpSession, lcSource, lcTarget)
ENDFOR
= InternetCloseHandle (hFtpSession)
= InternetCloseHandle (hOpen)
ENDIF
FUNCTION connect2ftp (strHost, strUser, strPwd)
** Abrimos el acceso.
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)
IF hOpen = 0
? "No tiene acceso a WinInet.Dll"
RETURN .F.
ENDIF
** Connect to FTP.
hFtpSession = InternetConnect (hOpen, strHost, 0,
strUser, strPwd, 1, 0,
0)
IF hFtpSession = 0
** Close
= InternetCloseHandle (hOpen)
? "FTP " + strHost + " not ready"
RETURN .F.
ELSE
? "Conectado a " + strHost + " como: [" +
strUser + ", *****]"
ENDIF
RETURN .T.
**--------------------------------------------
** Copia del/los archivos
**--------------------------------------------
FUNCTION local2ftp (hConnect, lcSource, lcTarget)
** Upload local file to ftp server
hSource = FOPEN (lcSource)
IF (hSource = -1)
RETURN -1
ENDIF
** New file in ftp server
hTarget = FtpOpenFile(hConnect, lcTarget,
GENERIC_WRITE, 2, 0)
IF hTarget = 0
= FCLOSE (hSource)
RETURN -2
ENDIF
lnBytesWritten = 0
lnChunkSize = 512 && 128, 512
DO WHILE Not FEOF(hSource)
lcBuffer = FREAD (hSource, lnChunkSize)
lnLength = Len(lcBuffer)
IF lnLength > 0
1
lnBytesWritten = lnBytesWritten + lnLength
? lnBytesWritten
** Show Progress
ELSE
EXIT
ENDIF
ELSE
EXIT
ENDIF
ENDDO
= InternetCloseHandle (hTarget)
= FCLOSE (hSource)
RETURN lnBytesWritten
Can someone give me some sample code has to how to
initate
a file transfer from within Foxpro.
I have an import and export routine that sure could use
such a thing
Thanks
Glen
-----Original Message-----
We are distributing a foxpro application that uses
Microsoft FTP to send files back to the server.
Malicious
users dumped files on our Win 2K server when the ftp
service was perpetually enabled. So, I have a a few
1. Is it possible to send files to our server from
within
a (remotely running) foxpro application without using
ftp,
say using http instead of ftp.
2. Is there a way that the ftp service can be started
and
stopped on the Win2k Server from within a foxpro
application running remotely?
3. Are there any other ways of sending small files to
our
server from a remotely running foxpro application?
Thank you.
Humty
.
.
Eric den Doop
2003-08-02 10:27:43 UTC
Permalink
Hello, Glen!
You wrote on Fri, 1 Aug 2003 16:20:21 -0700:

GW> Can someone give me some sample code has to how to initate
GW> a file transfer from within Foxpro.
GW> I have an import and export routine that sure could use
GW> such a thing

Download the free FTPCLASS from the universalthread for a complete FTP
solution written in VFP.
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
Humty
2003-08-04 15:11:39 UTC
Permalink
Thank you all for your help!

-Humty
-----Original Message-----
We are distributing a foxpro application that uses
Microsoft FTP to send files back to the server. Malicious
users dumped files on our Win 2K server when the ftp
service was perpetually enabled. So, I have a a few
1. Is it possible to send files to our server from within
a (remotely running) foxpro application without using
ftp,
say using http instead of ftp.
2. Is there a way that the ftp service can be started and
stopped on the Win2k Server from within a foxpro
application running remotely?
3. Are there any other ways of sending small files to our
server from a remotely running foxpro application?
Thank you.
Humty
.
Glen Wagner
2003-08-05 00:05:38 UTC
Permalink
Heberto
I got the posting down.
But
I am having troubles retrieving.
in particular ftpfindfirstfile and internetfindnext file
could i bother you for an example of those also :)
BTW
with what I have learned from you last week I have created
a web cam so I can watch my cat lye around the house all
day while I am working :)
thanks
Glen
-----Original Message-----
**
** Upload files to ftp server
**
#DEFINE GENERIC_READ 2147483648 && &H80000000
#DEFINE GENERIC_WRITE 1073741824 && &H40000000
PUBLIC hOpen, hFtpSession
DECLARE INTEGER InternetOpen IN wininet.dll;
STRING sAgent,;
INTEGER lAccessType,;
STRING sProxyName,;
STRING sProxyBypass,;
STRING lFlags
DECLARE INTEGER InternetCloseHandle IN wininet.dll;
INTEGER hInet
DECLARE INTEGER InternetConnect IN wininet.dll;
INTEGER hInternetSession,;
STRING sServerName,;
INTEGER nServerPort,;
STRING sUsername,;
STRING sPassword,;
INTEGER lService,;
INTEGER lFlags,;
INTEGER lContext
DECLARE INTEGER FtpOpenFile IN wininet.dll;
INTEGER hFtpSession,;
STRING sFileName,;
INTEGER lAccess,;
INTEGER lFlags,;
INTEGER lContext
DECLARE INTEGER InternetWriteFile IN wininet.dll;
INTEGER hFile,;
INTEGER lNumBytesToWrite,;
IF connect2ftp
("ftp.yourftpserver.com", "user", "password")
lcSourcePath = "C:\upload\" && local folder
lcTargetPath = "/www/" && remote folder (ftp
server)
lnFiles = ADIR (arr, lcSourcePath + "*.*")
FOR lnCnt=1 TO lnFiles
lcSource = lcSourcePath + LOWER (arr [lnCnt, 1])
lcTarget = lcTargetPath + LOWER (arr [lnCnt, 1])
? lcSource + " -> " + lcTarget
?? local2ftp (hFtpSession, lcSource, lcTarget)
ENDFOR
= InternetCloseHandle (hFtpSession)
= InternetCloseHandle (hOpen)
ENDIF
FUNCTION connect2ftp (strHost, strUser, strPwd)
** Abrimos el acceso.
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)
IF hOpen = 0
? "No tiene acceso a WinInet.Dll"
RETURN .F.
ENDIF
** Connect to FTP.
hFtpSession = InternetConnect (hOpen, strHost, 0,
strUser, strPwd, 1, 0,
0)
IF hFtpSession = 0
** Close
= InternetCloseHandle (hOpen)
? "FTP " + strHost + " not ready"
RETURN .F.
ELSE
? "Conectado a " + strHost + " como: [" +
strUser + ", *****]"
ENDIF
RETURN .T.
**--------------------------------------------
** Copia del/los archivos
**--------------------------------------------
FUNCTION local2ftp (hConnect, lcSource, lcTarget)
** Upload local file to ftp server
hSource = FOPEN (lcSource)
IF (hSource = -1)
RETURN -1
ENDIF
** New file in ftp server
hTarget = FtpOpenFile(hConnect, lcTarget,
GENERIC_WRITE, 2, 0)
IF hTarget = 0
= FCLOSE (hSource)
RETURN -2
ENDIF
lnBytesWritten = 0
lnChunkSize = 512 && 128, 512
DO WHILE Not FEOF(hSource)
lcBuffer = FREAD (hSource, lnChunkSize)
lnLength = Len(lcBuffer)
IF lnLength > 0
1
lnBytesWritten = lnBytesWritten + lnLength
? lnBytesWritten
** Show Progress
ELSE
EXIT
ENDIF
ELSE
EXIT
ENDIF
ENDDO
= InternetCloseHandle (hTarget)
= FCLOSE (hSource)
RETURN lnBytesWritten
Can someone give me some sample code has to how to
initate
a file transfer from within Foxpro.
I have an import and export routine that sure could use
such a thing
Thanks
Glen
-----Original Message-----
We are distributing a foxpro application that uses
Microsoft FTP to send files back to the server.
Malicious
users dumped files on our Win 2K server when the ftp
service was perpetually enabled. So, I have a a few
1. Is it possible to send files to our server from
within
a (remotely running) foxpro application without using
ftp,
say using http instead of ftp.
2. Is there a way that the ftp service can be started
and
stopped on the Win2k Server from within a foxpro
application running remotely?
3. Are there any other ways of sending small files to
our
server from a remotely running foxpro application?
Thank you.
Humty
.
.
Heberto Villavicencio
2003-08-05 01:11:23 UTC
Permalink
Sorry, no examples for ftpfindfirstfile and internetfindnext but find in
MSDN online

"Glen Wagner" <***@hotmail.com> escribi� en el mensaje news:86bd01c35ae5$4d36e640$***@phx.gbl...
Heberto
I got the posting down.
But
I am having troubles retrieving.
in particular ftpfindfirstfile and internetfindnext file
could i bother you for an example of those also :)
BTW
with what I have learned from you last week I have created
a web cam so I can watch my cat lye around the house all
day while I am working :)
thanks
Glen
-----Original Message-----
**
** Upload files to ftp server
**
#DEFINE GENERIC_READ 2147483648 && &H80000000
#DEFINE GENERIC_WRITE 1073741824 && &H40000000
PUBLIC hOpen, hFtpSession
DECLARE INTEGER InternetOpen IN wininet.dll;
STRING sAgent,;
INTEGER lAccessType,;
STRING sProxyName,;
STRING sProxyBypass,;
STRING lFlags
DECLARE INTEGER InternetCloseHandle IN wininet.dll;
INTEGER hInet
DECLARE INTEGER InternetConnect IN wininet.dll;
INTEGER hInternetSession,;
STRING sServerName,;
INTEGER nServerPort,;
STRING sUsername,;
STRING sPassword,;
INTEGER lService,;
INTEGER lFlags,;
INTEGER lContext
DECLARE INTEGER FtpOpenFile IN wininet.dll;
INTEGER hFtpSession,;
STRING sFileName,;
INTEGER lAccess,;
INTEGER lFlags,;
INTEGER lContext
DECLARE INTEGER InternetWriteFile IN wininet.dll;
INTEGER hFile,;
INTEGER lNumBytesToWrite,;
IF connect2ftp
("ftp.yourftpserver.com", "user", "password")
lcSourcePath = "C:\upload\" && local folder
lcTargetPath = "/www/" && remote folder (ftp
server)
lnFiles = ADIR (arr, lcSourcePath + "*.*")
FOR lnCnt=1 TO lnFiles
lcSource = lcSourcePath + LOWER (arr [lnCnt, 1])
lcTarget = lcTargetPath + LOWER (arr [lnCnt, 1])
? lcSource + " -> " + lcTarget
?? local2ftp (hFtpSession, lcSource, lcTarget)
ENDFOR
= InternetCloseHandle (hFtpSession)
= InternetCloseHandle (hOpen)
ENDIF
FUNCTION connect2ftp (strHost, strUser, strPwd)
** Abrimos el acceso.
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)
IF hOpen = 0
? "No tiene acceso a WinInet.Dll"
RETURN .F.
ENDIF
** Connect to FTP.
hFtpSession = InternetConnect (hOpen, strHost, 0,
strUser, strPwd, 1, 0,
0)
IF hFtpSession = 0
** Close
= InternetCloseHandle (hOpen)
? "FTP " + strHost + " not ready"
RETURN .F.
ELSE
? "Conectado a " + strHost + " como: [" +
strUser + ", *****]"
ENDIF
RETURN .T.
**--------------------------------------------
** Copia del/los archivos
**--------------------------------------------
FUNCTION local2ftp (hConnect, lcSource, lcTarget)
** Upload local file to ftp server
hSource = FOPEN (lcSource)
IF (hSource = -1)
RETURN -1
ENDIF
** New file in ftp server
hTarget = FtpOpenFile(hConnect, lcTarget,
GENERIC_WRITE, 2, 0)
IF hTarget = 0
= FCLOSE (hSource)
RETURN -2
ENDIF
lnBytesWritten = 0
lnChunkSize = 512 && 128, 512
DO WHILE Not FEOF(hSource)
lcBuffer = FREAD (hSource, lnChunkSize)
lnLength = Len(lcBuffer)
IF lnLength > 0
1
lnBytesWritten = lnBytesWritten + lnLength
? lnBytesWritten
** Show Progress
ELSE
EXIT
ENDIF
ELSE
EXIT
ENDIF
ENDDO
= InternetCloseHandle (hTarget)
= FCLOSE (hSource)
RETURN lnBytesWritten
Can someone give me some sample code has to how to
initate
a file transfer from within Foxpro.
I have an import and export routine that sure could use
such a thing
Thanks
Glen
-----Original Message-----
We are distributing a foxpro application that uses
Microsoft FTP to send files back to the server.
Malicious
users dumped files on our Win 2K server when the ftp
service was perpetually enabled. So, I have a a few
1. Is it possible to send files to our server from
within
a (remotely running) foxpro application without using
ftp,
say using http instead of ftp.
2. Is there a way that the ftp service can be started
and
stopped on the Win2k Server from within a foxpro
application running remotely?
3. Are there any other ways of sending small files to
our
server from a remotely running foxpro application?
Thank you.
Humty
.
.
g***@gmail.com
2019-05-27 14:11:53 UTC
Permalink
**** Uploading file to ftp **** Starting*****
**** Uploading file to ftp **** Starting*****

#DEFINE GENERIC_READ 2147483648 && &H80000000
#DEFINE GENERIC_WRITE 1073741824 && &H40000000

Local m.ftpServer, m.ftpUserName, m.ftpUserPass

PUBLIC hOpen, hFtpSession
DECLARE INTEGER InternetOpen IN wininet.dll;
STRING sAgent,;
INTEGER lAccessType,;
STRING sProxyName,;
STRING sProxyBypass,;
STRING lFlags

DECLARE INTEGER InternetCloseHandle IN wininet.dll;
INTEGER hInet

DECLARE INTEGER InternetConnect IN wininet.dll;
INTEGER hInternetSession,;
STRING sServerName,;
INTEGER nServerPort,;
STRING sUsername,;
STRING sPassword,;
INTEGER lService,;
INTEGER lFlags,;
INTEGER lContext

DECLARE INTEGER FtpOpenFile IN wininet.dll;
INTEGER hFtpSession,;
STRING sFileName,;
INTEGER lAccess,;
INTEGER lFlags,;
INTEGER lContext

DECLARE INTEGER InternetWriteFile IN wininet.dll;
INTEGER hFile,;
STRING @ sBuffer,;
INTEGER lNumBytesToWrite,;
INTEGER @ dwNumberOfBytesWritten

m.ftpServer="klingon"
m.ftpServer="172.10.1.3"
m.ftpUserName="e2userdp"
m.ftpUserPass="e2user"

IF connect2ftp (m.ftpServer, m.ftpUserName, m.ftpUserPass)
lcSourcePath = "C:\" && local folder
lcTargetPath = "/home/e2userdp/" && remote folder (ftp server)

lnFiles = ADIR (arr, lcSourcePath + "lolo.txt")

FOR lnCnt=1 TO lnFiles
lcSource = lcSourcePath + LOWER (arr [lnCnt, 1])
lcTarget = lcTargetPath + LOWER (arr [lnCnt, 1])
? lcSource + " -> " + lcTarget
?? local2ftp (hFtpSession, lcSource, lcTarget)
ENDFOR

= InternetCloseHandle (hFtpSession)
= InternetCloseHandle (hOpen)
ENDIF

FUNCTION connect2ftp (strHost, strUser, strPwd)
** Open the access
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)

IF hOpen = 0
? "No access to WinInet.Dll"
RETURN .F.
ENDIF

** Connect to FTP.
hFtpSession = InternetConnect (hOpen, strHost, 0, strUser, strPwd, 1, 0,
0)

IF hFtpSession = 0
** Close
= InternetCloseHandle (hOpen)
? "FTP " + strHost + " not ready"
RETURN .F.
ELSE
? "Connected to " + strHost + " as: [" + strUser + ", *****]"
ENDIF
RETURN .T.


**--------------------------------------------
** Copying files
**--------------------------------------------
FUNCTION local2ftp (hConnect, lcSource, lcTarget)
** Upload local file to ftp server
hSource = FOPEN (lcSource)
IF (hSource = -1)
RETURN -1
ENDIF

** New file in ftp server
hTarget = FtpOpenFile(hConnect, lcTarget, GENERIC_WRITE, 2, 0)
IF hTarget = 0
= FCLOSE (hSource)
RETURN -2
ENDIF
lnBytesWritten = 0
lnChunkSize = 512 && 128, 512
DO WHILE Not FEOF(hSource)
lcBuffer = FREAD (hSource, lnChunkSize)
lnLength = Len(lcBuffer)
IF lnLength > 0
IF InternetWriteFile (hTarget, @lcBuffer, lnLength, @lnLength) =
1
lnBytesWritten = lnBytesWritten + lnLength
? lnBytesWritten
** Show Progress
ELSE
EXIT
ENDIF
ELSE
EXIT
ENDIF
ENDDO

= InternetCloseHandle (hTarget)
= FCLOSE (hSource)

RETURN lnBytesWritten

**** Uploading file to ftp **** Ending *****





**** Download file from ftp **** Starting*****
**** Download file from ftp **** Starting*****
--------------------------------------------------
** FTP_DownLoad
**
** Download files from ftp server
**

PARAMETERS lcHost, lcUser, lcPwd, lcRemoteFile, lcNewFile, lnXFerType

*...........................................................................
......
*: Usage: DO ftpget WITH ;
*: 'ftp.host', 'name', 'password', 'source.file', 'target.file'[, 1
| 2]
*:
*: Where: lcHost = Host computer IP address or name
*: lcUser = user name - anonymous may be used
*: lcPwd = password
*: lcRemoteFile = source file name
*: lcNewFile = target file name
*: lnXFerType = 1 (default) for ascii, 2 for binary
*...........................................................................
......

*...set up API calls

DECLARE INTEGER InternetOpen IN wininet;
STRING sAgent, INTEGER lAccessType, STRING sProxyName,;
STRING sProxyBypass, STRING lFlags

DECLARE INTEGER InternetCloseHandle IN wininet INTEGER hInet

DECLARE INTEGER InternetConnect IN wininet.DLL;
INTEGER hInternetSession,;
STRING lcHost,;
INTEGER nServerPort,;
STRING lcUser,;
STRING lcPassword,;
INTEGER lService,;
INTEGER lFlags,;
INTEGER lContext

DECLARE INTEGER FtpGetFile IN wininet;
INTEGER hftpSession, ;
STRING lcRemoteFile,;
STRING lcNewFile, ;
INTEGER fFailIfExists,;
INTEGER dwFlagsAndAttributes,;
INTEGER dwFlags, ;
INTEGER dwContext

lcHost = ALLTRIM(lcHost)
lcUser = ALLTRIM(lcUser)
lcPwd = ALLTRIM(lcPwd)
lcRemoteFile = ALLTRIM(lcRemoteFile)
lcNewFile = ALLTRIM(lcNewFile)

sAgent = "vfp"

sProxyName = CHR(0) &&... no proxy
sProxyBypass = CHR(0) &&... nothing to bypass
lFlags = 0 &&... no flags used

*... initialize access to Inet functions
hOpen = InternetOpen (sAgent, 1,;
sProxyName, sProxyBypass, lFlags)

IF hOpen = 0
WAIT WINDOW "Unable to get access to WinInet.Dll" TIMEOUT 2
RETURN
ENDIF

*... The first '0' says use the default port, usually 21.
hftpSession = InternetConnect (hOpen, lcHost,;
0, lcUser, lcPwd, 1, 0, 0) &&... 1 = ftp protocol

IF hftpSession = 0
*... close access to Inet functions and exit
= InternetCloseHandle (hOpen)
WAIT WINDOW "Unable to connect to " + lcHost + '.' TIMEOUT 2
RETURN
ELSE
WAIT WINDOW "Connected to " + lcHost + " as: [" + lcUser + "]" TIMEOUT 1
ENDIF

*... 0 to automatically overwrite file
*... 1 to fail if file already exists
fFailIfExists = 0
dwContext = 0 &&... used for callback

WAIT WINDOW 'Transferring ' + lcRemoteFile + ' to ' + lcNewFile + '...'
NOWAIT
lnResult = FtpGetFile (hftpSession, lcRemoteFile, lcNewFile,;
fFailIfExists, 128, lnXFerType,;
dwContext)

*... 128 = #define FILE_ATTRIBUTE_NORMAL 0x00000080
*... See CreateFile for other attributes

* close handles
= InternetCloseHandle (hftpSession)
= InternetCloseHandle (hOpen)

IF lnResult = 1
*... successful download, do what you want here
WAIT WINDOW 'Completed.' nowait
ELSE
WAIT WINDOW "Unable to download selected file" TIMEOUT 2
ENDIF

RETURN

**** Download file from ftp **** Ending *****

Loading...