Forums
How to read a csv file from SFTP using python? - Printable Version

+- Forums (https://bdn.bdb.ai)
+-- Forum: BDB Knowledge Base (https://bdn.bdb.ai/forumdisplay.php?fid=13)
+--- Forum: BDB Data Pipeline (https://bdn.bdb.ai/forumdisplay.php?fid=48)
+---- Forum: BDB Data Pipeline Q & A (https://bdn.bdb.ai/forumdisplay.php?fid=17)
+---- Thread: How to read a csv file from SFTP using python? (/showthread.php?tid=346)



How to read a csv file from SFTP using python? - shreekantgosavi - 12-21-2022

Using python script component.
Paste below script in meta information script section.
Provide connection credentials.

import pandas as pd
import paramiko
def myconnect():
   ssh = paramiko.SSHClient()
   ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
   ssh.connect('localhost',port=22,username='user',password='123456')
   #print("connected suceessfully to SFTP Server")
   sftp_client = ssh.open_sftp()
   sftp_client.chdir('/home/user/folder_name')
   df= pd.read_csv(sftp_client.open('/home/user/folder_name/file_name.csv'))
   sftp_client.close()
   ssh.close()
   return df