You Are Here:

Community: Developer Discussion Boards

#1 Old Update my application files - 2008-10-02, 23:40

Join Date: May 2008
Posts: 81
nufun
Offline
Regular Contributor
My application uses pictures and files (text and pictures) that I would like to keep up-to-date. I would like to put a folder on a web server and give users the possibility to connect and download the whole content: how can I automatically copy all these files to my device folder?

Thanks.
Reply With Quote

#2 Old Re: Update my application files - 2008-10-03, 07:35

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by nufun View Post
My application uses pictures and files (text and pictures) that I would like to keep up-to-date. I would like to put a folder on a web server and give users the possibility to connect and download the whole content: how can I automatically copy all these files to my device folder?

Thanks.
hi nufun

If i understand your problem correctly then what you can do is make a particlular time in your application using timers and then using the urllib module you can retrieve whatever you want to your device and use that in your application.

hope this helps you
Enjoy Pythoning
Gaba88


Gargi Das- http://gargidas.blogsot.com

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Reply With Quote

#3 Old Re: Update my application files - 2008-10-03, 09:02

Join Date: May 2008
Posts: 81
nufun
Offline
Regular Contributor
It's not necessary that download is automatic (I put a menu button with "Update" and it's enough), what I need is to download all the remote files: could it be done just with python or do I need to put some script on the web server? (for example, I created a php script to list all the file into remote folder: am I in the right direction?).
Thanks.
Reply With Quote

#4 Old Re: Update my application files - 2008-10-03, 09:10

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
If I understood the situation right you could do it simply with Python. Here is an example of how to download a file.
Last edited by bogdan.galiceanu : 2008-10-03 at 09:22. Reason: Made post clearer
Reply With Quote

#5 Old Re: Update my application files - 2008-10-03, 09:41

Join Date: May 2008
Posts: 81
nufun
Offline
Regular Contributor
Ok, that's good, but in this way I guess I need to know the name of my up-to-dated files.
I think my main question is: is it possible to list all files in a remote folder just with python? I supposed something like
Code:
webserver = 'http://www.exemple.com/'
remote_folder = webserver + 'myfiles/'
f_list = os.listdir(remote_folder)
for file in f_list:
	url = remote_folder + file
	tempfile = "e:\\" + file
	try:
		print "Retrieving information..."
		urllib.urlretrieve(url, tempfile)
		lock=e32.Ao_lock()
		content_handler = appuifw.Content_handler(lock.signal)
		content_handler.open(tempfile)
		# Wait for the user to exit the image viewer.
		lock.wait()
		print "Video viewing finished."
	except:
		print "Problems."
but os.dir() doesn't work on remote folder (or I wasn't able to make it works! )
If so, I guess I need to retrieve my file list with php or something else.
Reply With Quote

#6 Old Re: Update my application files - 2008-10-03, 10:13

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Well, I'm not too knowledgeable when it comes to PHP so I'll suggest something else: have a list containing the names of the files that are to be updated, on the server. Read that list and use the names in it to download all the files you need.
Reply With Quote

#7 Old Re: Update my application files - 2008-10-03, 11:21

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by nufun View Post
Ok, that's good, but in this way I guess I need to know the name of my up-to-dated files.
I think my main question is: is it possible to list all files in a remote folder just with python? I supposed something like
Code:
webserver = 'http://www.exemple.com/'
remote_folder = webserver + 'myfiles/'
f_list = os.listdir(remote_folder)
for file in f_list:
	url = remote_folder + file
	tempfile = "e:\\" + file
	try:
		print "Retrieving information..."
		urllib.urlretrieve(url, tempfile)
		lock=e32.Ao_lock()
		content_handler = appuifw.Content_handler(lock.signal)
		content_handler.open(tempfile)
		# Wait for the user to exit the image viewer.
		lock.wait()
		print "Video viewing finished."
	except:
		print "Problems."
but os.dir() doesn't work on remote folder (or I wasn't able to make it works! )
If so, I guess I need to retrieve my file list with php or something else.
Hi,

Well, after long time I see something regarding PHP on this Forum

Here is how you can list all files using PHP scripting, you can use this to make a function of your own.

Code:
function dirList ($directory) 
{

    // create an array to hold directory list
    $results = array();

    // create a handler for the directory
    $handler = opendir($directory);

    // keep going until all files in directory have been read
    while ($file = readdir($handler)) {

        // if $file isn't this directory or its parent, 
        // add it to the results array
        if ($file != '.' && $file != '..')
            $results[] = $file;
    }

    // tidy up: close the handler
    closedir($handler);

    // done!
    return $results;

}
Hope it helps,

Best Regards,
Croozeus
Reply With Quote

#8 Old Re: Update my application files - 2008-10-03, 11:34

Join Date: May 2008
Posts: 81
nufun
Offline
Regular Contributor
Ok, I wrote about php but don't think I'm that good with it!
BTW your script is similar to mine, but I didn't think to put everything in an array!
Maybe this is exactly what I needed!
Thanks a lot!
I'll let you know if it works!!
Reply With Quote

#9 Old Re: Update my application files - 2008-10-03, 11:35

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by nufun View Post
Ok, I wrote about php but don't think I'm that good with it!
BTW your script is similar to mine, but I didn't think to put everything in an array!
Maybe this is exactly what I needed!
Thanks a lot!
I'll let you know if it works!!
I would be glad to help. I have done PHP tasks lately and so have the touch and feel of it

Best Regards,
Croozeus
Reply With Quote

#10 Old Re: Update my application files - 2008-10-03, 12:48

Join Date: May 2008
Posts: 81
nufun
Offline
Regular Contributor
Sorry, but this is my really first attempt to use python with php.

I've called your function, insert my folder and if I try to print output I see my array of values.
Then I worked on python so I used
Code:
list_file = urllib.urlopen(url_update).read()
print list_file
but after it connected, nothing happens. After a while it tries to connect again and again and so on.
I guess I'm doing something wrong.
Here are my doubts:
PHP: should i print my result or just return it?
Python: is the .read() method correct or should I use something else?
Sorry if they are silly questions.
Reply With Quote

#11 Old Re: Update my application files - 2008-10-03, 14:33

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by nufun View Post
Sorry, but this is my really first attempt to use python with php.
No problem, there is always opportunity to learn

Quote:
Originally Posted by nufun View Post
Code:
list_file = urllib.urlopen(url_update).read()
print list_file
but after it connected, nothing happens. After a while it tries to connect again and again and so on.
I guess I'm doing something wrong.
Here are my doubts:
PHP: should i print my result or just return it?
Python: is the .read() method correct or should I use something else?
You have to print the result on the client side or display it in any other form.
If you use http connection, the below line should do the job.

Code:
   response=conn.getresponse()
You need to print response variable here.

Just call the PHP script. read() function should do the job.

Best Regards,
Croozeus
Reply With Quote

#12 Old Re: Update my application files - 2008-10-03, 14:48

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by nufun View Post
Code:
list_file = urllib.urlopen(url_update).read()
print list_file
but after it connected, nothing happens. After a while it tries to connect again and again and so on.
hi nufun

you are doing nothing wrong with the code because .read() function will only read the url link.
What you try is retrieve the link at your phones memory than open it.

Hope you got it
Enjoy Pythoning
Gaba88


Gargi Das- http://gargidas.blogsot.com

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Reply With Quote

#13 Old Re: Update my application files - 2008-10-04, 17:10

Join Date: May 2008
Posts: 81
nufun
Offline
Regular Contributor
Ok, I got it working in some way (not still exactly what I want, but I'm working on it ).
Now my other problem is: how do I prevent my app from searching an access point when I'm already connected to one (it's actually asking me for an AP for every file it has to download)? And how I close connection with my connected access point when there is no file to download? I've tried with .close() method but it doesn't work.
Thanks for all your support.
Reply With Quote

#14 Old Re: Update my application files - 2008-10-05, 04:42

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by nufun View Post
Ok, I got it working in some way (not still exactly what I want, but I'm working on it ).
Now my other problem is: how do I prevent my app from searching an access point when I'm already connected to one (it's actually asking me for an AP for every file it has to download)? And how I close connection with my connected access point when there is no file to download? I've tried with .close() method but it doesn't work.
Thanks for all your support.
You can't prevent, the python application to ask for access point, but you can make it ask just for once.

Use the following function to create a default access point for your application.

Code:
def set_accesspoint():
    apid = socket.select_access_point()
    if appuifw.query(u"Do you want to set this as default access point","query") == True:
        f = open('C:\\data\\wc\\apid.txt','w')
        f.write(repr(apid))
        f.close()
        appuifw.note(u"Saved default access point ", "info")
        apo = socket.access_point(apid)
        socket.set_default_access_point(apo)
For closing the connections, I would recommend to use iapconnect connection, as it has 2 functions - close and stop.

Code:
#conn.close() # this will disconnect, but leave gprs active
conn.stop() # this will shutdown the gprs connection
where conn is

Code:
conn = iapconnect.Connection()
Hope that helps,

Best Regards,
Croozeus
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Application Log Files kalnyc1 Installation, Certification and Security 8 2008-10-02 21:39
Update resource files for PhoneBook (N73) heuven Installation, Certification and Security 3 2008-04-03 07:57
How to add new files to the application in CodeWarrior? jennie Carbide.c++ IDE and plug-ins 3 2007-09-13 08:43
Can a PC suite application visit all the files of phone? inter_fan PC Suite API and PC Connectivity SDK 4 2007-08-10 19:12
problem in files downloading in mobile application KrishnaMegha Browsing and Mark-ups 1 2007-04-10 22:14

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia