I’m scripting an install script in python.
How do I download file from ftp in python?
Operating system — Windows XP – if that makes a difference.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a code snippet I’m currently using.
Usage:
Then you can use
reqas a file-like object and e.g. useshutil.copyfileobj()to copy the file contents into a local file. If the MIME type doesn’t matter simply remove that part of the code.Since you seem to be lazy, here’s code downloading the file directly to a local file:
This method is smart enough to use the filename sent by the server if you specify a path ending with a slash, otherwise it uses the destination you specified.