0

I need to store the files in STFP client to pandas dataframe to better process it. I am new to paramiko, could someone please help me with this? Thank you!

Below is my code:

df1 = pd.Dataframe

sftp = paramiko.SFTPClient.from_transport(transport)

remote_path = "/ppreports/outgoing/" 

localdir = 'D:\work\paypal_SFTP' 
# list all reports
reports = sftp.listdir(remote_path) 

## Everything works fine here, I am able to get all files in this direc

### now I wanted to open this filename1.CSV

with sftp.open('filename1.CSV', "w") as f:
    df1 = pd.read_csv(sftp.open(remote_path))
### and now it gives "OSError: General failure"

#the get step works fine too

sftp.get(remote_path, localdir)
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
user3429999
  • 17
  • 1
  • 7
  • @MartinPrikryl Thank you so much for the help, I did manage to get it store in dataframe, but i found that it isn't the same format as the one I got from sftp.get() even if I split it with delimiters, there are always some " " marks in the value. Are there any ways to avoid this and make it exact format and content for the results from sftp.get() and sftp.open function? Thank you ! – user3429999 Jun 17 '21 at 02:56
  • @MartinPrikryl I need to remove all the " marks(like the value is "123", only keep 123) , I could do it by using pandas replace(' " ', '') to replace all the " value to empty, but that would also remove all the " that SHOULD be kept. I couldn't seem to find a solution for this, would you please give some suggestions? Thank you! – user3429999 Jun 17 '21 at 03:09
  • @MartinPrikryl for sftp.get() all It does was just download the csv to my local path (sftp.get(remote_path, localpath) )when I use sftp.open to store it as dataframe, then delimite it with comma, and then output it using to_csv() to get csv file. The value from csv file drive from sftp.open-dataframe-to_csv(), all values are quoted with "", where the csv from sftp.get() does not have those "". – user3429999 Jun 17 '21 at 05:41
  • @MartinPrikryl sftp.get(remote_path, localdir) This is everything i did with sftp.get() and This is what I did with sftp.open with sftp.open(remote_path) as f: f.prefetch() df = pd.DataFrame(f) df = df[0].str.split(',',expand=True) df.to_excel('333.xlsx') after that I just compare both file in excel. – user3429999 Jun 17 '21 at 07:48
  • and the one created by sftp.open() - dataframe - to csv has "" for each value, but the one downloaded through sftp.get doesn't – user3429999 Jun 17 '21 at 07:49

0 Answers0