I think my question sounds kinda stupid but I'm pretty new to python programming.
I just want to have a text variable which gets a string from a .txt file at an FTP server.
So in conclusion: There is a .txt File stored at an FTP server and I want to have the content of this file stored in an variable...
This is what I have so far... Can anybody help me? I use Python 3.6.3 :) thanks in advance!
from ftplib import FTP
ftp = FTP('1bk2t.ddns.net')
ftp.login(user='User', passwd = 'Password')
ftp.cwd('/path/')
filename = 'filename.txt'
ftp.retrbinary("RETR " + filename, open(filename, 'wb').write)
ftp.quit()
var = localfile.read
If you want to download a text file contents to memory, without using any temporary file, use
retrlines
like:Or use an array: