Python! Download Trimble GPS Almanac via FTP

Written by Kevin Bell,


Using Trimble Pathfinder Office, one must download the current ephemeris file monthly, so why not automate it somewhat!  This code is what you'll find if you Google for FTP & Python, so I've altered the code a bit to hit Trimble's FTP site. You'll want to save this script in your C:\Program Files\Common Files\Trimble\Almanacs directory. Once it's in that directory, you can either click the script to update, or you could set it up as a scheduled task. Thanks to Matt Croydon (whoever you are?) for putting together a nice example for the rest of us to use!  Note that this script is similiar to another post that hits an FTP site from an index feature class, so check them out side by side to look at how versatile a little code can be!

#currentGPSalmanac.py
# Author: Matt Croydon < This e-mail address is being protected from spam bots, you need JavaScript enabled to view it >, referencing many sources. Modified by Kevin Bell...

from ftplib import FTP

# This will handle the data being downloaded
# It will be explained shortly
def handleDownload(block):
    file.write(block)
    print ".",

# Optionally, you could specify username and password:
# FTP('hostname', 'username', 'password')
ftp = FTP('ftp.trimble.com')

print 'Logging in.'
# You can specify username and password here if you like:
# ftp.login('username', 'password')
# Otherwise, it defaults to Anonymous
print ftp.login()

# This is the directory that we want to go to
directory = 'pub/eph'

print 'Changing to ' + directory
ftp.cwd(directory)

filename = 'current.ssf'

# Open a file for writing in binary mode
print 'Opening local file ' + filename
file = open(filename, 'wb')

# Download the file a chunk at a time
# Each chunk is sent to handleDownload
# We append the chunk to the file and then print a '.' for progress
# RETR is an FTP command
print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, handleDownload)

# Clean up time
print 'Closing file ' + filename
file.close()

print 'Closing FTP connection'
print ftp.close()



Users' Comments  
 

No comment posted

Add your comment

03, Jun. 2008
Last Updated ( 03, Jun. 2008 )