dataframe to ftp 1

dataframe to ftp

from ftplib import *
from io import StringIO
import pandas
import io

ftp = FTP('')
ftp.login('un', 'pw')
buffer = StringIO.StringIO()
text = buffer.getvalue()
bio = io.BytesIO(str.encode(text))

ftp.storbinary('STOR filename.csv', bio)

Here is what the above code is Doing:
1. Connect to the FTP server
2. Login to the FTP server
3. Change the working directory to the directory where you want to store the file
4. Create a buffer to store the file
5. Convert the pandas dataframe to a csv file and store it in the buffer
6. Convert the buffer to a byte stream
7. Store the byte stream on the FTP server

Similar Posts