Download files from FTP

Moderator: Rathinagiri

Post Reply
User avatar
zolysoftsolutions
Posts: 139
Joined: Wed Feb 29, 2012 3:33 am
Location: Gyulakuta, Erdélyország
Contact:

Download files from FTP

Post by zolysoftsolutions »

Hi all,

I just searched the forum by keyword "FTP" and returns no issues found. Is possible in HMG 3.1.1 to download files from FTP?
Thank you in advance.

Best regards,
Zoli B.
[u]Moderator Notes[/u] (Pablo César) wrote:This topic was moved from HMG Wishlist.
_______________________________
Open eyes for you!
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Download files from FTP

Post by Pablo César »

zolysoftsolutions wrote:I just searched the forum by keyword "FTP" and returns no issues found.
This most probably is an forum system limitation (in php) for searching strings.
Is possible in HMG 3.1.1 to download files from FTP?
Yes, sure !
There is an example in:

C:\MiniGUI\SAMPLES\Advanced\FtpClient\demo.prg

But there is a faster protocol than ftp, test with http, you can see my example in this brazilian forum: http://www.pctoledo.com.br/forum/fileba ... t=c&page=1 and another from colleague Marek here: http://hmgforum.com/viewtopic.php?p=3924#p3924
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
zolysoftsolutions
Posts: 139
Joined: Wed Feb 29, 2012 3:33 am
Location: Gyulakuta, Erdélyország
Contact:

Re: Download files from FTP

Post by zolysoftsolutions »

Thank you very much Pablo.

I was not attent enough. It was near my eyes and I don't see the solution. : )
Thank you again.

Best regards,
Zoli B.
_______________________________
Open eyes for you!
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Download files from FTP

Post by mol »

Code: Select all

PROCEDURE DownloadFromWWW
	param cURL, cLocalFileName, lSilent
	LOCAL oCon, oUrl, i, cResponse
	local ret := .f.
	local oErrorHandler
	
	oErrorHandler := ErrorBlock({|e| break(e)})
	
	BEGIN SEQUENCE
	cLocalFileName := alltrim(cLocalFileName)
	if lSilent = NIL
		lSilent := .f.
	endif
	oUrl := tURL():New( cUrl )
	IF Empty( oUrl )
		if !lSilent
			MsgBox('Wrong url address: ' + cUrl)
		endif
		BREAK
	ENDIF

	IF oUrl:cProto != "http"
		if !lSilent
			MsgBox('Wrong http address')
		endif
		BREAK
	END
   
	oCon := TipClientHttp():New( oUrl )
	oCon:nConnTimeout := 20000
	if !lSilent
		MsgBox("Connecting with "+ oUrl:cServer)
	endif
	IF oCon:Open( cUrl )
		if !lSilent
			MsgBox("Connectio established." +chr(10)+"Press OK to download " + oUrl:cPath +oUrl:cFile)
		endif
		oCon:WriteAll(cLocalFileName)
		if !lSilent
			MsgBox("Downloaded and saved as: "+cLocalFileName)
		endif
		oCon:Close()
		ret := .t.
	ELSE
		IF oCon:SocketCon == NIL
			cResponse := "Connection not initialised"
		ELSEIF hb_InetErrorCode( oCon:SocketCon ) == 0
			cResponse := oCon:cReply
		ELSE
			if !lSilent
				cResponse := "Error in connection: " + hb_InetErrorDesc( oCon:SocketCon )
			endif
		ENDIF
		if !lSilent
			MsgBox("I can't connect: "+ oUrl:cServer+chr(10)+"Server answer: "+cResponse)
		endif
		ret := .f.
	END
	RECOVER
		if !lSilent
			MSGSTOP("Error in connectio with server!"+chr(10)+"try to download manually")
		endif
	END SEQUENCE
	ErrorBlock(oErrorHandler)
RETURN ret
User avatar
zolysoftsolutions
Posts: 139
Joined: Wed Feb 29, 2012 3:33 am
Location: Gyulakuta, Erdélyország
Contact:

Re: Download files from FTP

Post by zolysoftsolutions »

Thank you very much Marek,

Is very usefoull procedure, but I have to downoad trough FTP. I just downloaded HMG 3.1.1, but
I haven't Advanced folder in Samples. I need the FTPClient sample.

I found the sample.. in Minigui : )

Regards,
Zoli B.
_______________________________
Open eyes for you!
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Download files from FTP

Post by mol »

try do download harbour nightly sources and you'll find all samples there.
I'm attaching contrib\hbtip folder from harbour
Attachments
hbtip.zip
(97.8 KiB) Downloaded 365 times
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: Download files from FTP

Post by sudip »

Great! Thanks a lot ;-)
With best regards,
Sudip
Post Reply