Upload an Download Problem^^

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Upload an Download Problem^^

Post by MasterchiefJB » Tue Jan 05, 2010 9:54 am

Hi all,

thanks to revolution and the community I am learning revolution day by day but there are some topics I am not aware of.

I have 2 problems I am trying to solve for 2 days now.
1. Problem The Upload Problem
I ask for a file and upload the result to the server

Code: Select all

 
answer file "Select ZIP file to upload:"
   put it into uploadFile
   
   
   local tDestination
   put "ftp:// "& FTPUSER &":"& FTPPASS & "@" & "rockraidersunited.org/lego/" & uploadFile  into tDestination
The File is uploaded but also the Directory structure (ex. instad of Test.zip is this uploaded: C:/MyApp/Test.zip
How do I upload just the selected file but without the Directory structure?

2. Problem The Download Problem

I search on the server for files and these files are listened in a Filelist (works great)
Now I try to select the files via the Filelist and try to download them (doesn´t work). I don´t have a hunch why it isn´t working and that´s why I am really confused.

Code: Select all

on mouseUp
  
  -- put the selection of the ModListFile into the Variable tFileToDownload
  put the hilitedLine of field "ModList" into tHilitedLine
  put line tHilitedLine of field "ModList" into tFileToDownload
    -- put the address of the file to download into a variable
  put "ftp:// "& FTPUSER &":"& FTPPASS & "@" & "rockraidersunited.org/lego/" into tDownloadLink 
    put tFileToDownload after tDownloadLink
   libURLSetStatusCallback "showProgress", the long name of me
  libURLDownloadToFile tDownloadLink,newmod.zip ,"showProgress"
  
    
    -- put tDownloadLink & tFileToDownload into tDownloadLink
    -- set up a message to show the status of the download as it progresses
  
    
    -- make sure the progress bar is hidden, as this property is used to initialize it
    hide scrollbar "ProgressBar"
    put empty into field "ProgressField"
    put 0 into sDownloadStart
    
    -- start the download process, telling Rev to call the "downloadComplete" handler when finished
 --  load URL tDownloadLink with message "downloadComplete"
end mouseUp

Any help will be appreciated

Thanks,
Masterchief

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Upload an Download Problem^^

Post by Klaus » Tue Jan 05, 2010 1:54 pm

Hi chief,

Upload: you are only providing the PATH to your file!
Extract the "pure" filename and it should work
Try this:

Code: Select all

answer file "Select ZIP file to upload:"
   put it into uploadFile
  ## "uploadFile" is now contains the string "C:/MyApp/Test.zip", but you need to supply only "Test.zip"
  set itemdel to "/"
  put item -1 of uploadFile into uploadFileName
  local tDestination
  put "ftp:// "& FTPUSER &":"& FTPPASS & "@" & "rockraidersunited.org/lego/" & uploadFilename  into tDestination

Download

Are you sure that this is not working? The script looks OK.
You are providing a relative filename to the "liburldownloadtofile" handler, so this might work, but the resulting file is not where you exspect it!
...
libURLDownloadToFile tDownloadLink,"newmod.zip" ,"showProgress"
...
Please quote filenames and strings in general!

If there are not any errors then the fiel should be found in the "defaultfolder".
Try to supply an absolute pathname to that handler like:
...
libURLDownloadToFile tDownloadLink,"C:/MyApp/newmod.zip","showProgress"
...

You should also check if you have write permission in that folder!

Hope that helps.


Best

Klaus

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: Upload an Download Problem^^

Post by MasterchiefJB » Tue Jan 05, 2010 4:29 pm

Thanks Klaus! You solved my Upload Problem.

To the Download Problem: I don´t know why I get this error by trying to download the files from the server. The FTP Account I am using has read and write permissions, so that can´t be the problem. Is there a way that my app can check wheter the file I am trying to download is availeable on the server (maybe with subdirectories) before trying to download it? Well I am really confused about this because of the fact that this code here works perfectly for retrieving the files on the server:

Code: Select all

 libURLSetFTPListCommand "NLST"
     
   
   put URL "ftp:// "& FTPUSER &":"& FTPPASS & "@" & "rockraidersunited.org/lego/" into field "ModList"
And this code for downloading the file worked great on my Localhost but now I am using a real FTP Server it doesn´t download the file (as said before)

Code: Select all

 put the hilitedLine of field "ModList" into tHilitedLine
  put line tHilitedLine of field "ModList" into tFileToDownload
    -- put the address of the file to download into a variable
  put "ftp:// "& FTPUSER &":"& FTPPASS & "@" & "rockraidersunited.org/lego/" into tDownloadLink 
    put tFileToDownload after tDownloadLink
   libURLSetStatusCallback "showProgress", the long name of me
  libURLDownloadToFile tDownloadLink,newmod.zip ,"showProgress"

Well I am confused^^
I would be glad if you or anybody else could help me again

Regards,
Masterchief

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Upload an Download Problem^^

Post by Klaus » Tue Jan 05, 2010 4:39 pm

What error do you get when you try to download the file?

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Upload an Download Problem^^

Post by Klaus » Tue Jan 05, 2010 4:41 pm

I just noticed that there is a SPACE after "ftp:// " in your scripts!
Just a typo in this posting?

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: Upload an Download Problem^^

Post by MasterchiefJB » Wed Jan 06, 2010 5:31 pm

Removed the space after ftp:// and now I don´t get an error but the file wasn´t downloaded too!
I mean if it downloads the file it should show me the Progressbar but that doesn´t happen.
What to do now?

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Upload an Download Problem^^

Post by bangkok » Wed Jan 06, 2010 5:40 pm

Ok. I have a set of scripts (in one button) that are working. Hope it can help.

Code: Select all

on goDownload
   ask file "Where to save the file ?" with fld "filename" as sheet
   if the result is "cancel" then exit to top
   put it into bb
   
   put "ftp://"& FTPUSER &":"& FTPPASS &"@"& FTPHOST &"/"& fld "filename" into aa
   
   libURLSetStatusCallback "showProgress", the long name of me
   
   libURLDownloadToFile aa,bb,"downloadComplete"
end goDownload

on downloadComplete
   hide scrollbar "progressbar"
   answer "Download done"
end downloadComplete

on showProgress pURL, pStatus
     if the number of items in pStatus = 3 then
      if the visible of scrollbar "ProgressBar" = false then
         put the last item of pStatus into tTotalBytes
         set the startValue of scrollbar "ProgressBar" to 0
         set the endValue of scrollbar "ProgressBar" to tTotalBytes
         show scrollbar "ProgressBar"
      end if
      set the thumbPosition of scrollbar "ProgressBar" to item 2 of pStatus
   end if
end showProgress

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: Upload an Download Problem^^

Post by MasterchiefJB » Wed Jan 06, 2010 6:27 pm

I pasted this code into an new button and what I get is this error message:
" executing at 6:26:48 PM
Type Chunk: no such object
Object Button
Line ask file "Where to save the file ?" with fld "filename" as sheet
Hint filename"

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Upload an Download Problem^^

Post by Klaus » Wed Jan 06, 2010 7:50 pm

Hi Chief,

do you have a field named "filename" somehwere on your card as OBVIOUSLY used in the script?
If not, c'mon, then you can't of course use other peoples script 1:1!
:shock:


Best

Klaus

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: Upload an Download Problem^^

Post by MasterchiefJB » Fri Jan 08, 2010 4:29 pm

Well it´s not working, but I may have somthing that could be helpfull.
As you know I have a listbox where the user selects a listened file and presses the download button.
with this code I get the filename of the selected file:

Code: Select all

 put the hilitedLine of field "ModList" into tHilitedLine
  put line tHilitedLine of field "ModList" into tFileToDownload
so the variable tFileToDownload should contain the filename of the file to download but what I realized is that it doesn´t contain the filename. It contains the number of the item in the listbox. So how can I change this that it gives me the filename back instead the number of the entry in the listbox? I think this will solve my problem.

Regards,
Masterchief

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Upload an Download Problem^^

Post by Klaus » Fri Jan 08, 2010 7:37 pm

Hi Chief,

hmmm:
...
put the hilitedLine of field "ModList" into tHilitedLine
put line tHilitedLine of field "ModList" into tFileToDownload
...
SHOULD put the selected filename into the variable "tFileToDownload"!
Works fine her in my quick test!

->put the hilitedLine of field "ModList"
The first line gives you the line number: X

->put line tHilitedLine of field "ModList"
and this gives you the TEXT of line X.

You could try this:
-> put the selectedtext of fld "ModList" into tFileToDownload

Same as above, but a oneliner :-)

What do you finally get in "tFileToDownload"?
-> answer tFileToDownload
or
-> put tFileToDownload
So you see the content of the variable in the message box.

Maybe this will give us a hint.


Best

Klaus

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: Upload an Download Problem^^

Post by MasterchiefJB » Sat Jan 09, 2010 8:08 pm

Hell, you are right. On: Answer tFileToDownload it gives me the filename back. So that´s working but it doesn´t solve the problem

This is how the code looks like now:

Code: Select all

 -- put the selection of the ModListFile into the Variable tFileToDownload
  put the hilitedLine of field "ModList" into tHilitedLine
  put line tHilitedLine of field "ModList" into tFileToDownload
  -- put the address of the file to download into a variable
  answer "Downloading:" && tFileToDownload
  put "ftp://"& FTPUSER &":"& FTPPASS &"@"&"rockraidersunited.org/lego/" into tDownloadLink 
    put tFileToDownload after tDownloadLink
   libURLSetStatusCallback "showProgress", the long name of me
  libURLDownloadToFile tDownloadLink,newmod.zip ,"showProgress"
Another thing I realized is that the file "newmod.zip" is created after I pressed the download button but it is empty (0KB)
Maybe something there is wrong?

Well I did also a test with the tDownloadLink variable but it contains everything it should:
ftp://ftpuser:password@rockraidersunited.org/lego/Lego Backup.zip

Obviously I didn´t post the login data but I would like to add that the ftpusername also contains an @ and maybe it is this @ that creates the problem.

@Klaus: Would you like me to send you my stack file so you can take a look at it?

Regards,
Masterchief

Edit: I really don´t know why the Progressbar doesn´t appear when I try to download something, this leads me to the opinion that the StatusCallback code isn´t executed at all.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Upload an Download Problem^^

Post by bangkok » Sat Jan 09, 2010 10:34 pm

MasterchiefJB wrote:

Code: Select all

 
  libURLDownloadToFile tDownloadLink,newmod.zip ,"showProgress"
Another thing I realized is that the file "newmod.zip" is created after I pressed the download button but it is empty (0KB)
Maybe something there is wrong?
I don't know what you do wrong. Maybe you have to provide a full file path for the file "newmod.zip", and not only its name (by the way, in your code, you seem to forgot the quotes for this filename).

Anyway.

Here is my example in a stack. It goes to a public ftp server of sun.com, to download a small file (500 kb), with the progress bar.

It's working with me, it should work with you. :D
Attachments
DOWNLOAD.zip
(1005 Bytes) Downloaded 309 times

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: Upload an Download Problem^^

Post by MasterchiefJB » Sun Jan 10, 2010 12:04 pm

Indeed your script works fine but as soon as I try to use it for my own app by modding it a littlebit it gives me an error.
For a quick test wheter it works for me I just placed this line in front of the goDownload call

Code: Select all

  put selectedText of fld "ModList" into fld "filename"
And this works the filename is show in the fld "Filename" but when it asks me where to save the file (with the filename as sheet) it gives me this error back: Invalid Filename (test file was named test.zip)

Hell this problem is really getting annoying!;) Thanks to everyone who is trying to help me^^

Regards,
Masterchief

@bangkok this is how your code looks like now:

Code: Select all

on mouseup
   put selectedText of fld "ModList" into fld "filename"
   goDownload
end mouseup

on goDownload
   ask file "Where to save the file ?" with fld "filename" as sheet
   if the result is "cancel" then exit to top
   
   put it into thePathToDownloadTheFile

   put "XXX" into FTPHOST 
   put "XXX" into FTPUSER
   put "XXX" into FTPPASS
   
   put "ftp://"& FTPUSER &":"& FTPPASS &"@"& FTPHOST &"/"& fld "filename" into aa
   
   libURLSetStatusCallback "showProgress", the long name of me
   
   libURLDownloadToFile aa,thePathToDownloadTheFile,"downloadComplete"
end goDownload

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Upload an Download Problem^^

Post by Klaus » Sun Jan 10, 2010 12:55 pm

Hi Chief,

OK, send me the stack:
klaus (AT) major-k.de


Best

Klaus

Post Reply