[Tutor] Best way to do FTP login?

Michael Selik michael.selik at gmail.com
Fri Jun 17 15:07:06 EDT 2016


On Fri, Jun 17, 2016 at 12:46 PM boB Stepp <robertvstepp at gmail.com> wrote:

> ftp = FTP('ip_address', 'username', 'password')
>
> Or
>
> ftp = FTP('ip_address')
> ftp.login('username', 'password')
>
> Most of the examples I am seeing online use the second approach.  Is
> there some reason why this is to be preferred?


Not that I can see. Perhaps only to show that the login method exists.
I suggest using it in a context manager.

    py> with FTP('ftp.example.com', 'username', 'password') as ftp:
    ...     ftp.dir()


More information about the Tutor mailing list