ช่วยเหลือ

1

How to download a csv file from a FTP server ?

Avatar
Totor

Hi, I wanna download a csv file from a FTP server but when I try with the line below, I have FileName.csv in my /home/openerp but the file is empty.


i = FileName.csv

pathdst = /home/openerp/

ftp.retrbinary('RETR ' + i, open(pathdst + os.sep + i, 'wb').write)


I think the problem comes from the fact it's a csv file because I used this line before with a txt file and it worked.


In advance, thanks.

Avatar
Discard
1 Answer
1
Avatar
Motez
Best Answer

There should be no difference between csv and txt files. I'm using this code to handle all files extensions without any problems. Make sure the path in your ftp server is correct if so make sure you are closing the ftp connection and the file after using them :

file = open(pathdst + os.sep + i, 'wb')
ftp.retrbinary('RETR ' + i, file.write)
ftp.close()
file.close()
Avatar
Discard