Nripen das
Programmer
upload a file to my domain server through ftp in vfp code, i have domain / user id / and password
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
-------------------------------------------------
**
** Upload files to ftp server
**
#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