Calling ftp commands from python

Maurice LING mauriceling at acm.org
Wed Aug 31 20:57:24 EDT 2005


Thierry Lam wrote:
> Is it possible to run an ftp command to connect to some remote computer
> on the network.
> 
> For example, if I want to retrieve some data from
> \\remcomputer\datafiles on the network and copy it to my local
> computer, how do I do it in python on the Unix side?
> 
> I don't want to use mount since I don't have permission.
> 
> Thanks
> Thierry
> 

I use ftplib in the standard libraries.

from ftplib import FTP

def grab_geneontology():
     """Function to download gene ontology file."""
     ftp = FTP('ftp.geneontology.org')
     ftp.login()
     ftp.cwd('/pub/go/ontology')
     ftp.retrbinary('retr gene_ontology.obo', 
open('gdata/gene_ontology', 'wb').write)
     ftp.quit()

if __name__ == '__main__': grab_geneontology()

maurice



More information about the Python-list mailing list