Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

upload a file to my domain server through ftp in vfp code

Status
Not open for further replies.

Nripen das

Programmer
Nov 2, 2021
1
0
1
IN
upload a file to my domain server through ftp in vfp code, i have domain / user id / and password
 
Was there a question here?



If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Maybe this would help:

Code:
-------------------------------------------------
**
** 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

Not my work, I googled 'How to upload...'
and got this link


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Hi,

FTP is no longer possible with a lot of providers nowadays, because it’s not secure. My hosting partner stopped supporting FTP already a few years ago.

I now use WINSCP for uploading files to my secure webserver. You can script WinSCP to make it work with VFP.
Now the best part: WinSCP is free!

Good luck!

Regards, Gerrit
 
We wrote a custom FTP app to send files back-and-forth using a non-standard port and non-standard protocol. We also greatly simplified our server security in so doing.

--
Rick C. Hodgin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top