Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending or Receiving File from or to FTP
Message
From
21/05/2018 13:35:53
 
 
To
21/05/2018 12:46:18
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows Server 2012 R2
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01660045
Message ID:
01660231
Views:
55
I'm sorry, but I don't use the code myself. But you have the source code, try to step through it.

>Hello Tore,
>
>This morning i will test the script above with sucess
>
>#DEFINE INTERNET_INVALID_PORT_NUMBER 0
>#DEFINE INTERNET_OPEN_TYPE_DIRECT 1
>#DEFINE INTERNET_SERVICE_FTP 1
>#DEFINE FTP_TRANSFER_TYPE_ASCII 1
>#DEFINE FTP_TRANSFER_TYPE_BINARY 2
>#DEFINE GENERIC_READ 0x80000000
>#DEFINE GENERIC_WRITE 0x40000000
>
>PUBLIC hOpen, hFtpSession
>DO declare
>
>* select FTP connection on which you an appropriate access level
>* in all cases it can not be any "anonymous" access
>IF connect2ftp("ftp.biglevel.pt", "username", "mypassword")
>	lcSourcePath = "C:\ftpenvia\"       && local source directory
>	lcTargetPath = "testeLuis/send/"       && ftp destination directory
>	lnFiles = ADIR(arr, lcSourcePath + "*.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)
>
>	*DO RenomearFicheiro With lcSourcePath
>
>ENDIF
>
>PROCEDURE declare
>	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;
>		INTEGER hFile, STRING @sBuffer,;
>		INTEGER lBytesToWrite, INTEGER @dwBytesWritten
>
>FUNCTION connect2ftp(strHost, strUser, strPwd)
>	* open access to Inet functions
>	hOpen = InternetOpen("vfp", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0)
>
>	IF hOpen = 0
>		? "Unable to get access to WinInet.Dll"
>		RETURN .F.
>	ENDIF
>
>	* connect to FTP
>	hFtpSession = InternetConnect(hOpen, strHost, INTERNET_INVALID_PORT_NUMBER,;
>		strUser, strPwd, INTERNET_SERVICE_FTP, 0, 0)
>
>	IF hFtpSession = 0
>	* close access to Inet functions and exit
>		= InternetCloseHandle(hOpen)
>		? "FTP " + strHost + " is not available"
>		RETURN .F.
>	ELSE
>		? "Connected to " + strHost + " as: [" + strUser + ", *****]"
>	ENDIF
>RETURN .T.
>
>FUNCTION local2ftp(hConnect, lcSource, lcTarget)
>* copying local file to the remote target
>	hSource = FOPEN(lcSource)
>	IF (hSource = -1)
>		RETURN -1
>	ENDIF
>
>	* this call creates a new remote file
>	hTarget = FtpOpenFile(hConnect, lcTarget, GENERIC_WRITE,;
>		FTP_TRANSFER_TYPE_BINARY, 0)
>	IF hTarget = 0
>		= FCLOSE(hSource)
>		RETURN -2
>	ENDIF
>
>	lnBytesWritten = 0
>	lnChunkSize = 256	&& 128, 512, 16384 and so on are Ok
>
> 	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
>				* at this point you can display the progress
>				* and test events: keyboard, mouse etc.
>				* to decide on aborting the upload
>				?? "?"	&& you can put link to a progress bar here instead
>			ELSE
>				EXIT
>			ENDIF
>		ELSE
>			EXIT
>		ENDIF
>	ENDDO
>	= InternetCloseHandle(hTarget)
>	= FCLOSE(hSource)
>RETURN lnBytesWritten
>
>
>
>Now, i receive this message
>Connected to ftp.biglevel.pt as:[biglevel,*****]
>C:\ftpenvia\memo.txt -> testeLuis/send/memo.tx1-2 ??
>
>I don´t know why these message and how to solve the problem also.
>Could you give me some help.
>
>Many thanks,
>Luis Santos
Previous
Reply
Map
View

Click here to load this message in the networking platform