FTP文件关闭查询

2024-06-16 14:28:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的逻辑文件检索使用FTP。有谁能告诉我是否需要明确关闭FTP连接?是否需要关闭文件?在做这种操作时抓住错误是一个好的做法吗?在

ftp = ftplib.FTP("xx.xxx.xxx.xxx")
ftp.login("UID", "PSW")
ftp.retrbinary('RETR %s' % filename, open(filename, 'w').write)

Tags: 文件uid错误ftploginopenfilenamexxx
1条回答
网友
1楼 · 发布于 2024-06-16 14:28:25

上的python文档ftp.退出方法

FTP.quit()

Send a QUIT command to the server and close the connection. This is the “polite” way to close a connection, but it may raise an exception if the server responds with an error to the QUIT command. This implies a call to the close() method which renders the FTP instance useless for subsequent calls (see below).

ftp文档没有提到关闭文件句柄,但是关闭打开的文件总是一个很好的实践。在

相关问题 更多 >