Upload files to a web server by FTP.

This module uploads files to (typically) a website via FTP. Details of the upload destination are stored in the file weather.ini in your data directory. You should be able to get the required information from your web space provider. If your provider allows SFTP then you could use pywws.service.sftp for greater security.

  • Example weather.ini configuration:

    site =
    user = xxxxxxx
    password = zzzzzzzzz
    directory = public_html/weather/data/
    port = 21
    plot = ['24hrs.png.xml', 'rose_12hrs.png.xml']
    text = ['24hrs.txt']
    services = [('ftp', '24hrs.txt', '24hrs.png', 'rose_12hrs.png')]

Run pywws.service.ftp once to set the default configuration, which you can then change. directory is the name of a directory in which all the uploaded files will be put. This will depend on the structure of your web site and the sort of host you use. port is the port number to use. 21 is the standard value but your web space provider may require a different port.

You can upload any files you like, as often as you like, but typical usage is to update a website once an hour. Each file to be uploaded needs to be listed in a service entry like ('ftp', 'filename'). If the file is not in your work directory’s output directory then filename should be the full path.


ToService(context[, check_params])
class pywws.service.ftp.ToService(context, check_params=True)[source]

Bases: pywws.service.FileService

config = {'directory': ('', True, None), 'password': ('', True, None), 'port': ('21', True, None), 'site': ('', True, None), 'user': ('', True, None)}
logger = <Logger pywws.service.ftp (WARNING)>
service_name = 'ftp'

Context manager factory function for a batch of one or more uploads.

This makes it easy to ensure any resources such as an internet connection are properly closed after a batch of uploads. Use the contextlib.contextmanager() decorator when you implement this method.

For a typical example, see the source code of the pywws.service.openweathermap module. If your upload can’t benefit from a session object yield None, as in pywws.service.copy.

upload_file(session, path)[source]

Comments or questions? Please subscribe to the pywws mailing list and let us know.