1
ftp 서버의 파일 이름 목록을 처리하라는 요청이 있습니다. 그러나 파일 이름에는 아시아 문자 및 기타 알 수없는 문자가 포함됩니다. 그래서 어느 파일명이 iso-8859-1에 의해 해독 될 수있는 gb2312에 의해 해독 될 수 있는지 판단 할 필요가있다. 즉, gb2312를 사용하여 파일 이름 목록을 가져올 수 없다면 iso-88591-1을 사용하십시오. 그래서 당신은 많은 코드를 포함하지 않는 FTPLIBpython3에서 ftplib의 인 코드/디코드 정보
def retrlines(self, cmd, callback = None):
"""Retrieve data in line mode. A new port is created for you.
Args:
cmd: A RETR, LIST, NLST, or MLSD command.
callback: An optional single parameter callable that is called
for each line with the trailing CRLF stripped.
[default: print_line()]
Returns:
The response code.
"""
if callback is None: callback = print_line
resp = self.sendcmd('TYPE A')
##################I need to update here############################
with self.transfercmd(cmd) as conn, \
conn.makefile('r', encoding='iso-8859-1') as fp:
###################################################################
while 1:
line = fp.readline()
print(line)
if self.debugging > 2: print('*retr*', repr(line))
if not line:
break
if line[-2:] == CRLF:
line = line[:-2]
elif line[-1:] == '\n':
line = line[:-1]
callback(line)
return self.voidresp()