Trying to get a progress bar working for a ftp upload

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Trying to get a progress bar working for a ftp upload

Post by admin12 » Thu Jul 28, 2011 7:33 pm

Yes, I watched the controls training and studied the progress bar part very carefully. I cannot extrapolate what I need from it in this case.

The user needs to upload files to the file server and I thought a progress bar would make a nice touch.

Here is the code that uploads the ftp files and FTPs.

=================================
-- was invisible, now show it.
show the sb "prgScrollBar"
set the startvalue of sb "prgScrollBar" to 1

# Start by getting the file to upload
local tFileForUpload, tFileName
answer file "Select a file to upload"
put it into tFileForUpload

# Get the name of the file for upload
set the itemdel to "/"
put the last item of tFileForUpload into tFileName
put empty into field 1
put empty into field "fldRef1"

# Connect the start the upload
local tDestination
put "http://www." & "travelandworkusa.com" &FilePath &tFileName into tFieldDest
put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & "ftp.travelandworkusa.com" &FilePath & tFileName into tDestination
libURLSetStatusCallback "uploadProgress", the long ID of me
libURLftpUploadFile tFileForUpload, tDestination, "uploadComplete"
put tFieldDest into field "fldRef1"
end mouseUp

on uploadComplete pURL, pStatus
put "Status Update:" && pStatus && return after field "lblHints"
set the thumbpos of sb "prgScrollBar" to xyz
end uploadComplete

on uploadProgress pURL, pStatus
put "Status Update:" && pStatus && return before field "lblHints"
set the thumbpos of sb "prgScrollBar" to xyz
end uploadProgress

=========================================

Is this line

set the thumbpos of sb "prgScrollBar" to xyz

in the right place and how do I 'plug it in' to the value of the ftp upload?

I need to figure out the end position of the progress bar by finding out the total size of the file being uploaded - how do I do this?

Mike

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: Trying to get a progress bar working for a ftp upload

Post by admin12 » Thu Jul 28, 2011 8:31 pm

Anyone?

Mike

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Trying to get a progress bar working for a ftp upload

Post by SparkOut » Fri Jul 29, 2011 12:29 am

You need to look at libURLSetStatusCallback in the dictionary a little more, but you are getting there I think.

From the docs:
The URL status parameter is similar to the status returned by the URLStatus function, and is one of the following:

"queued": on hold until a previous request to the same site is completed
"contacted": the site has been contacted but no data has been sent or received yet
"requested": the URL has been requested
"loading,bytesReceived,bytesTotal": the URL data is being received
"uploading,bytesReceived,bytesTotal": the file is being uploaded to the URL
"downloaded": the application has finished downloading the URL
"uploaded": the application has finished uploading the file to the URL
"error": an error occurred and the URL was not transferred
"timeout": the application timed out when attempting to transfer the URL
empty: the URL was not loaded, or has been unloaded
So in your uploadProgress handler you can check if item 1 of pStatus is "uploading" then item 3 should tell you how large the file is. You can then use that to calculate and set the endValue of the scrollbar. (Note that the maximum endValue is 65535, and as the status parameter returns the number of bytes for the size of the file, you will probably have to do some dividing by 10s/100s/1000s to get a value within range. You may also want to set a flag that indicates the endValue has already been calculated and set, to avoid needless resetting of the endValue each time the handler is called.)
Then you should be able to take item 2 of pStatus and apply the same division, and use that to set the thumbPos.

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

Re: Trying to get a progress bar working for a ftp upload

Post by Klaus » Fri Jul 29, 2011 11:55 am

admin12 wrote:Anyone?
Mike
Mike, please stop opening two threads for the same topic, thanks!

And I will move this thread to the "Internet" forum.

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

Re: Trying to get a progress bar working for a ftp upload

Post by bangkok » Fri Jul 29, 2011 5:21 pm

Here is a small example.

Be sure to set your parameters (ftp server address, login and password) in the stack script.
Attachments
UPLOADFTP.zip
(4.64 KiB) Downloaded 512 times

Post Reply