mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-18 18:14:34 +08:00
Fix ResourceWarning: unclosed file (#681)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
This commit is contained in:

committed by
Libin Yang

parent
3dc50529ca
commit
2d70e9f747
@ -20,10 +20,9 @@ ftp.cwd('/Enter the directory here/')
|
||||
|
||||
def ReceiveFile():
|
||||
FileName = 'example.txt' """ Enter the location of the file """
|
||||
LocalFile = open(FileName, 'wb')
|
||||
ftp.retrbinary('RETR ' + FileName, LocalFile.write, 1024)
|
||||
with open(FileName, 'wb') as LocalFile:
|
||||
ftp.retrbinary('RETR ' + FileName, LocalFile.write, 1024)
|
||||
ftp.quit()
|
||||
LocalFile.close()
|
||||
|
||||
"""
|
||||
The file which will be sent via the FTP server
|
||||
@ -32,5 +31,6 @@ def ReceiveFile():
|
||||
|
||||
def SendFile():
|
||||
FileName = 'example.txt' """ Enter the name of the file """
|
||||
ftp.storbinary('STOR ' + FileName, open(FileName, 'rb'))
|
||||
with open(FileName, 'rb') as LocalFile:
|
||||
ftp.storbinary('STOR ' + FileName, LocalFile)
|
||||
ftp.quit()
|
||||
|
Reference in New Issue
Block a user