Info: Networking: URLlib, HTTP, FTP, SSL, TCP/IP socket

Downloading files from the net using URLlib:

Example (useful for simply downloading files from the net):


import urllib

url = "http://weather.gov/mdl/radar/rcm1pix_b.gif"
tempfile = "c:\\testimg.gif"
urllib.urlretrieve(url, tempfile)

Example script : urllib_example.py

 

Uploading parameters and files to the net and receiving a response:

HTTP post example (useful for uploading parameters and files to the net):

import httplib
import urllib


content = "hello"

params = urllib.urlencode({'data': content, 'eggs': 0, 'bacon': 0})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = httplib.HTTPConnection("www.exampleserver.com")
conn.request("POST", "/examplefolder/example.php", params, headers)
response = conn.getresponse()
conn.close()

Example script : http_post.py

Example php script : example.php

For encoding descriptions and other info regarding HTTP see: www.python.org

 

 

FTP example (useful e.g. for uploading files to a URL on the net):

NOTE: you need to install first the ftplib library to your phone before you can use ftp, because the Nokia Python for S60 package does not incude it by default. NOTE: You need to install the ftplib.py file on your phone as a python library (not a python script).

ftp library file: ftplib.py (comes originally with the desktop python version)

 

from ftplib import FTP

picselection = 'c:/testimg.gif'

ftp = FTP('www.exampleserver.com') # connect to host
ftp.set_pasv('true')
ftp.login('username','password') # login anonymous
ftp.cwd('public_html/examplefolder') # change directory where to store the image
F=open(picselection,'r')
ftp.storbinary('STOR image.gif',F,1024) # store the image
ftp.quit()
F.close()


Example script : ftp_example.py

For documentation regarding FTP see: www.python.org

 

SSL (useful e.g. for secure connections to the net):

Example script : SSL_example.py (script currently not available)

 

 

 

TCP/IP socket:

Connect your phone to a TCP/IP socket and communicate over it:

Example script for phone: tcp_socket_phone_client.py

Example script for PC: tcp_socket_pc_server.py

 

 

 

 

 

 

 

 

 

 

Previous|Next  | Menu        Copyright (c) 2006 Jurgen Scheible