Heberto Villavicencio
2003-08-02 00:53:25 UTC
**
** 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
** 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
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,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
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
.
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
.