How can I do an FTP transfer in Python?
Archive - Originally posted on "The Horse's Mouth" - 2011-10-05 19:22:14 - Graham Ellis"If you think someone's probably done it before, they probably have .... and it's probably available to you" A good answer to many questions of the form "can I do xxxxx in Python?"
Question today "can I do an FTP transfer from Python"
Answer "Yes" [but I had a look around and discovered there was on example on our web site!]
There IS an example now ;-) ... it's [here].
• The ftplib module is distributed with Python, but must be imported into programs in which you wish to use it.
• You create a connection object using the ftplib.FTP method.
• You login with the login method on the connection object.
They you can run a whole series of methods such as pwd and dir to find the current ditectory, and list the current directory.
Methods such as retrbinary can then be used to retrieve files, passing the file retrieval instruction into the FTP connection, and providing a callback which allows the author of the code to output to the screen, to a file, or to process it otherwise.