Problem downloading files from a website

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Hunam
Posts: 8
Joined: Wed May 29, 2019 9:08 am

Problem downloading files from a website

Post by Hunam » Wed May 29, 2019 9:18 am

I have a problem downloading a file from a website.

I'm using a button with this code :

Code: Select all

on mouseUp pMouseButton
   libURLDownloadToFile "ftp://fr.wordpress`.`org/latest-fr_FR.zip","%USERPROFILE%\desktop","Downloaded!"
end mouseUp
This is normal if the dot is surrounded by ``, it's because I'm not allowed to put links.

If you have an idea to solve this problem, feel free to share it with me.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Problem downloading files from a website

Post by bogs » Wed May 29, 2019 9:48 am

Perhaps this thread will help you.
Image

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problem downloading files from a website

Post by Klaus » Wed May 29, 2019 9:50 am

Hi Hunam,

hello and welcome to the forum! 8)

Due to a high spamming rate here, you need to have at least 10 postings before you can post links etc.

OK, here is what is going wrong:
1. You need to provide a FILENAME for the downloaded file
2. "%USERPROFILE%\desktop" is not a valid location in LC.
Use -> specialfolderpath("desktop") for this
Something like this will work:

Code: Select all

...
## Filename on your desktop:
put specialfolderpath("desktop") & "/latest-fr_FR.zip" into tFile
libURLDownloadToFile "ftp://fr.wordpress.org/latest-fr_FR.zip",tFile,"Downloaded!"
...
And don't forget to add USERNAME and PASSWORD for the FTP server like!

Code: Select all

...
libURLDownloadToFile "ftp://USERNAME:PASSWORD@fr.wordpress.org/latest-fr_FR.zip",tFile,"Downloaded!"
...
Best

Klaus

Hunam
Posts: 8
Joined: Wed May 29, 2019 9:08 am

Re: Problem downloading files from a website

Post by Hunam » Wed May 29, 2019 11:41 am

I tested it on a button, but it still doesn't work:

Code: Select all

on mouseUp pMouseButton
   libURLDownloadToFile "ftp://myusername:mypassword`@`ftpupload`.`net/htdocs/test-file.psd",specialfolderpath("desktop"),"Downloaded!"
end mouseUp
I put it in a web browser and it downloads the file:

Code: Select all

ftp://myusername:mypassword`@`ftpupload`.`net/htdocs/test-file.psd
Last edited by Hunam on Wed May 29, 2019 4:17 pm, edited 1 time in total.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problem downloading files from a website

Post by Klaus » Wed May 29, 2019 12:13 pm

Please read my posting again, you need to provide a FILENAME to download the file to, not just a FOLDER! 8)

Try this:

Code: Select all

on mouseUp
   libURLDownloadToFile "ftp://myusername:mypassword@ftpupload.net/htdocs/test-file.psd",(specialfolderpath("desktop") & "/test-file.psd"),"Downloaded!"
end mouseUp
And the last parameter must be the name of a HANDLER that will be called after the download has finished like this:

Code: Select all

on mouseUp
   libURLDownloadToFile "ftp://myusername:mypassword@ftpupload.net/htdocs/test-file.psd",(specialfolderpath("desktop") & "/test-file.psd"),"download_done"
end mouseUp

command download_done
   answer "File has been downloaded!"
end download_done
If in doubt check the dictionary for more infos.

Hunam
Posts: 8
Joined: Wed May 29, 2019 9:08 am

Re: Problem downloading files from a website

Post by Hunam » Wed May 29, 2019 12:53 pm

I'm so sorry but.. It's doesn't download the file, just shows the pop-up (And I've tested with a normal location, doesn't work either.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problem downloading files from a website

Post by Klaus » Wed May 29, 2019 1:00 pm

Hm, mysterious internet... :D

OK, the message that gets called after the download also receives two parameter
1. the url requested and
2. the status of the download
Try this:

Code: Select all

on mouseUp
   libURLDownloadToFile "ftp://myusername:mypassword@ftpupload.net/htdocs/test-file.psd",(specialfolderpath("desktop") & "/test-file.psd"),"download_done"
end mouseUp

command download_done tUrl,tStatus
   answer tStatus
end download_done
Then tell what the dialog reads, maybe that will give us a hint what might go wrong.
And I've tested with a normal location
What do you consider a "normal" location?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Problem downloading files from a website

Post by bogs » Wed May 29, 2019 1:05 pm

Klaus wrote:
Wed May 29, 2019 1:00 pm
What do you consider a "normal" location?
I was wondering that myself. Maybe they have a mysterious desktop :twisted:
Image

Hunam
Posts: 8
Joined: Wed May 29, 2019 9:08 am

Re: Problem downloading files from a website

Post by Hunam » Wed May 29, 2019 1:23 pm

It's working!
Congratulation!
Thanks a lot!

And for the normal location, I misspoke, I just meant without the"(specialfolderpath("desktop")" :lol:

And just a quick question, I saw in the disctionary that there is no"(specialfolderpath("")" for downloads, how do we do it then?

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problem downloading files from a website

Post by Klaus » Wed May 29, 2019 2:10 pm

Hi Hunam,

congratulations to YOU! :-)

If you leave out the folder, then the file will be downloaded to the current -> DEFAULTFOLDER
Wherever that may be...

Since most of the specialfolderpath names cannot be changed by the user (like Desktop), Download is a folder that the user CAN in fact change to whatever he/she likes. Maybe that is why there is no specialfolderpath for that.

Here some more (undocumented) specialfolderpath codes for Mac and Windows:
http://www.sonsothunder.com/devres/live ... ile010.htm

Best

Klaus

Hunam
Posts: 8
Joined: Wed May 29, 2019 9:08 am

Re: Problem downloading files from a website

Post by Hunam » Wed May 29, 2019 4:17 pm

I think no because I've move my "documents" folder (but I don't know if I've did this with an external software..)
But I did this for the default folder:

Code: Select all

libURLDownloadToFile "ftp://username:password@ftpupload`.`net/htdocs/test-file.psd",("/test-file.psd"),"download_done"
And the pop-up said "error", :lol:

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problem downloading files from a website

Post by Klaus » Wed May 29, 2019 4:22 pm

Leave out the slash and try again:

Code: Select all

...
libURLDownloadToFile "ftp://username:password@ftpupload`.`net/htdocs/test-file.psd","test-file.psd","download_done"
...
What platform are you on?

Hunam
Posts: 8
Joined: Wed May 29, 2019 9:08 am

Re: Problem downloading files from a website

Post by Hunam » Wed May 29, 2019 4:25 pm

Sorry but still not working.

I'm on Windows 10.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problem downloading files from a website

Post by Klaus » Wed May 29, 2019 4:45 pm

OK, what is in fact "the defaultfolder" at that point? Maybe you don't have write permission there?
Usually the folder containing Livecode.exe is the defaultfolder after you start LC and in the "Applications" folder only an ADMIN has write permission. I think on Widnwos that is named "Program files"?

Open the message box and type: answer the defaultfolder
Then hit ENTER, that may solve this mistery. :D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Problem downloading files from a website

Post by FourthWorld » Wed May 29, 2019 4:54 pm

Without checking error information the exercise becomes guesswork.

To see what LC may be telling you, check the result.

To see what the OS may be telling you, call the sysError function when the result is not empty.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Internet”