从ftp服务器读文件到内存不在客户端生成本地文件
def openFtpFileBytesIO(fileName,ftpServer,ftpUser='anonymous',ftpPass='',port=21):
"""
读ftp文件到缓存
"""
ftps = FTP()
ftps.connect(ftpServer,port)
ftps.login(ftpUser,ftpPass)
download_file = BytesIO()
ftps.retrbinary('RETR ' + str(fileName), download_file.write)
download_file.seek(0)
return download_file
def readFile(f):
while True:
line = f.readline()
if line:
print(line)
else:
f.close()
break
if __name__=="__main__":
f=openFtpFileBytesIO('test.csv','192.168.0.3')
readFile(f)