I am using python to download files from a ftp server and i am able to download the files but when i open the files they seem to be corrupted or are not opening Files like songs or jpgs are working fine but documents,excel sheets,pdfs and text files are not downloading properly.
Following is my code :
from ftplib import FTP
ftp = FTP()
ftp.connect(ip_address,port)
ftp.login(userid,password)
direc='directory path'
ftp.cwd(direc)
doc='doc.txt' or xlsx or pdf or jpg etc
download_path='path to download file on desktop'
file=open(download_path+ doc,'wb')
ftp.retrbinary(f"RETR {doc}", file.write)
I am able to download the required files but most of them are neing corrupted. What changes should i make to make the code work.