This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Possibility to specify port in __init__ of ftplib.FTP
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jack__d, vpjtqwv0101
Priority: normal Keywords:

Created on 2021-07-30 23:34 by vpjtqwv0101, last changed 2022-04-11 14:59 by admin.

Messages (4)
msg398611 - (view) Author: Marty (vpjtqwv0101) Date: 2021-07-30 23:34
I think all that's needed is to add new parameter port in __init__ and then add it to self.connect() as argument:
    def __init__(self, host='', port=0, user='', passwd='', acct='',
                 timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None, *,
				 encoding='utf-8'):
		self.encoding = encoding
        self.source_address = source_address
        self.timeout = timeout
        if host:
            self.connect(host, port)
            if user:
                self.login(user, passwd, acct)


Currently if I need to specify port, I have to do it like this:
with FTP() as ftp:
	ftp.connect(host, port)
	ftp.login(user, password)
	# my actions

I the port parameter would be added, I could use it like this:
with FTP(host, port, user, password) as ftp:
	# my actions

Thank you.
msg398620 - (view) Author: Jack DeVries (jack__d) * Date: 2021-07-31 02:24
The only thing to consider is that connections are flakey, and the user might typically want to explicitly handle them in most cases. Therefore, it's a better API if the .connect() call appears in the user's code.

If anything, it might be better to create a new context manager called Auto FTP connection or something, and include default error handling behavior.

Have you discussed this idea in python- ideas?
msg398621 - (view) Author: Jack DeVries (jack__d) * Date: 2021-07-31 02:25
> user might typically want to explicitly handle them in most cases.

*Explicitly handle exceptions
msg398653 - (view) Author: Marty (vpjtqwv0101) Date: 2021-07-31 17:47
Well, if it's possible to connect to ftp server within __init__, I think that adding port parameter makes sense.
I mostly don't need to handle connect() and login() separately. All I need is to connect to ftp server and work with it. If there is some trouble with connection or login, the code still can't continue in this case.

I haven't discussed this idea there. I'm going to create a topic for it and I will add the link here.
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 88951
2021-07-31 17:47:34vpjtqwv0101setmessages: + msg398653
2021-07-31 02:25:31jack__dsetmessages: + msg398621
2021-07-31 02:24:35jack__dsetnosy: + jack__d
messages: + msg398620
2021-07-30 23:34:00vpjtqwv0101create