Non mi fa scrivere l'oggetto: FTP
Buongiorno ho la necessità di inviare un file txt sul mio sito postato su altervista.
Ho seguito le indicazioni del tutorial su:
https://www.worthwebscraping.com, ebbene se faccio
la prova con il sito: dlptest.com, tutto funziona. Riesco a fare upload ed anche il donwload.
Non appena metto le credenziali del mio sito ricevo questo errore:
****************************************************************************************
Traceback (most recent call last):
File "C:/ftppy/ftpaiaz.py", line 9, in <module>
ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)
File "C:\Program Files\lib\ftplib.py", line 119, in __init__
self.connect(host)
File "C:\Program Files\lib\ftplib.py", line 160, in connect
self.welcome = self.getresp()
File "C:\Program Files\lib\ftplib.py", line 242, in getresp
resp = self.getmultiline()
File "C:\Program Files\lib\ftplib.py", line 228, in getmultiline
line = self.getline()
File "C:\Program Files\lib\ftplib.py", line 210, in getline
line = self.file.readline(self.maxline + 1)
File "C:\Program Files\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 104: invalid continuation byte
*************************************************************************************************
Il codice da me usato è:
import ftplib
FTP_HOST = "ftp.aiazzone.altervista.org"
FTP_USER = "aiazzone"
FTP_PASS = "***********"
# connect to the FTP server
ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)
# force UTF-8 encoding
ftp.encoding = "utf-8"
# local file name you want to upload
filename = "file.txt"
with open(filename, "rb") as file:
# use FTP's STOR command to upload the file
ftp.storbinary("STOR file.txt", file)
# the name of file you want to download from the FTP server
filename = 'file.txt'
with open(filename, "wb") as file:
# use FTP's RETR command to download the file
ftp.retrbinary("RETR file.txt", file.write)
# list current files & directories
ftp.dir()
# quit and close the connection
ftp.quit()
Grazie in anticipo per un eventuale aiuto.
Lanfranco Schillaci
laschil@gmail.com