I am unable to use ftp.storebinary to send .HTML files. HTML files are the only files I have run into so far. I can send all other files I have tried including but not limited to, .txt, .js , .jpg, .bmp ...
Operating system and architecture: Windows 11, Python 3.9.7
import ftplib
ftp = ftplib.FTP("ftpupload.net") # FTP URL
ftp.login("username", "password") # FTP ([Username],[Password])
ftpPath = '/test/'
ftp.cwd(ftpPath) # FTP directory
ftp.storbinary('STOR ' + 'index.html',
open(r'C:\Users\whybo\Desktop\index.html', 'rb'))
Transfering file using
ftp.storbinary()can get issues if your.htmlfile containing non-ASCII characters. Thus, your.htmlfile might contain non-ASCII characters, which are harmful and prevent you from sending the file.You can use
ftp.storlines()method which operates on ASCII mode and it can handle files containing non-ASCII characters like.htmlfiles.Last two lines of your code can be replaced by: