How to send CSV file directly to an FTP server

前端 未结 1 2072
北海茫月
北海茫月 2021-01-07 00:59

My question is How can I send a CSV file to an FTP server. As you can see, the following script is the current code of mine:

Code sample:

def downloa         


        
相关标签:
1条回答
  • 2021-01-07 01:54

    Write the CSV file to an in-memory file-like object (e.g. BytesIO) and upload that:

    from ftplib import FTP
    from io import BytesIO
    import csv
    
    flo = BytesIO() 
    writer = csv.writer(flo, delimiter=';')
    
    writer.writerow(...)
    
    ftp = FTP('ftp.example.com')
    ftp.login('username', 'password')
    
    flo.seek(0)
    ftp.storbinary('STOR test.csv', flo)
    
    0 讨论(0)
提交回复
热议问题