[Gambas-user] How to download a file?

Willy Raets willy at ...2734...
Wed Apr 4 02:05:31 CEST 2012


On wo, 2012-04-04 at 01:53 +0200, Willy Raets wrote:
> Oh..and you need components:
> - gb.net
> - gb.net.curl
> to make it work...
> 
> Good luck,
> 
> Willy
> 
> On wo, 2012-04-04 at 01:49 +0200, Willy Raets wrote:
> > On wo, 2012-04-04 at 00:44 +0200, Willy Raets wrote:
> > > Try this:
> > > 
> > > Dim sSourcePath, sCopyPath As String
> > > sSourcePath = "http://mydomain/test"

Looking at your original post again the file is not located at
http://mydomain/test but at http://www.mydomain.com/test

So sSourcePath should be:

sSourcePath = "http://www.mydomain.com/test"

> > > sCopyPath = User.Home & "/Test"
> > > If Not(Exist(sCopyPath) Then
> > >    MKDIR sCopyPath
> > > Endif
> > > sCopyPath = sCopyPath & "/test"
> > > If Exist(sCopyPath) Then
> > >    KILL sCopyPath
> > > Endif

Instead of:

> > > DownloadFile(sSourcePath)

You could do:

DownloadFile (sSourcePath, SCopyPath)

> > 
> > Forgot one line of code that needs to go here:
> > 
> > PUBLIC hGetFileClient AS NEW HttpClient AS "hGetFileClient"
> > 

You then need to change this

> > > PUBLIC SUB DownloadFile(sURL AS String)

to this:

PUBLIC SUB DownloadFile(sUrl As String, sLocPath As String)

> > > 
> > >   hGetFileClient.URL = sURL
> > >   hGetFileClient.TimeOut = 5
> > >   hGetFileClient.Async = TRUE

And change this

> > >   hGetFileClient.Get(User.Home & "/Test/test")

to this:

hGetFileClient.Get(sLocPath)

> > > 
> > > END
> > > 
> > > PUBLIC SUB hGetFileClient_Error()
> > > 
> > >   hGetFileClient.Stop()
> > > 
> > > END
> > > 
> > > PUBLIC SUB hGetFileClient_Finished()
> > > 
> > >   hGetFileClient.Stop()
> > > 
> > > END
> > > 
> > > 
> > > 
> > > On ma, 2012-03-26 at 14:25 -0700, abbat wrote:
> > > > I have a file on:
> > > > www.mydomain.com/test
> > > > 
> > > > I tried :
> > > > 
> > > > 
> > > > sSourcePath = "http://mydomain" 
> > > > sCopyPath = User.Home & "/Test/" 
> > > > Copy sSourcePath & "test" To sCopyPath & "test" 
> > > > 
> > > > but "File or Directory does not exist"
> > > > 
> > > > How to download a file?
> > > > Thanks

Hope you get the idea :-)






More information about the User mailing list