0

Here I have a function that is to upload a Dataframe to ftp server..

import pandas as pd
import paramiko
    
df42 = pd.to_csv('file.csv')

def uploadToSftp():
 ssh_client = paramiko.SSHClient()
 ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 ssh_client.connect(hostname='host',username='user_name',password='password')
 ftp_client= ssh_client.open_sftp()
 with ftp_client.open('/path/on/ftp/server/', "w") as f:
                  df42.to_csv(f , index=False))

The function runs but there is no file on the server, I can upload using terminal using the same remote folder path and it works..

I used this SO referance but still now working..

'https://stackoverflow.com/questions/55248832/how-to-transfer-pandas-dataframe-to-csv-on-sftp-using-paramiko-library-in-pytho'

James Cook
  • 334
  • 4
  • 16

1 Answers1

0

Something like the following would work

import pandas as pd
import paramiko


with ftp_client.open('/path/on/ftp/server/file.csv', 'w', bufsize=32768) as f:
     f.write(df42.to_csv(index=False))
Jroc561
  • 57
  • 1
  • 6