Python Forum
Opening CSV file from SFTP server not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Opening CSV file from SFTP server not working
#1
Hello,

So after two days of scavenging the internet I have not found anything to help solve my issue. Any help or recommendations would be appreciated.


What I'm trying to do: There is an SFTP server that has a .csv file on it that I need to read. Downloading the csv and reading it is not an option as I'm developing a website.

I am currently using paramiko to access the server. It connects successfully. I use the following line of code to open the csv

 file = sftp.open('fixed.csv')
The problems:
1) when I try to use pandas read_csv, it only displays the first row of elements.

Please note this also happens if I open the csv file from my local computer and not the SFTP. So I am assuming I am just using this wrong.


 csv = pandas.read_csv(file)
    for line in csv:
        print(line)
2) I also tried using the built in csv library. The problem here is that it will not open the file, and I get an error: "TypeError: expected str, bytes or os.PathLike object, not SFTPFile"

Please note that if I open the csv locally using this method, it works perfectly fine. So I am assuming the problem has something to do with the filetype.



with open(file) as csvfile:
        spamreader = csv.reader(csvfile)
        for line in spamreader:
            print(line)
I am at my wits end and have no idea how to proceed. Please let me know if I can provide additional information, thank you! Any help would be greatly appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python editor that will SFTP automatically on save sawtooth500 1 162 Apr-30-2024, 05:13 AM
Last Post: Gribouillis
  Timestamp of file changes if a share mapped to a server…. tester_V 34 4,045 Jul-04-2023, 05:19 AM
Last Post: tester_V
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 833 Feb-16-2023, 08:11 PM
Last Post: cubangt
  no such file or directory in SFTP saisankalpj 2 1,585 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
  file transfer via python SFTP SCP mg24 3 3,032 Sep-15-2022, 04:20 AM
Last Post: mg24
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,235 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
Question apk file not working on android polya001 0 1,166 Feb-06-2022, 11:58 PM
Last Post: polya001
  Facing Problem while opening a file through command prompt vlearner 4 1,943 Jan-30-2022, 08:10 AM
Last Post: snippsat
  How to take the tar backup files form remote server to local server sivareddy 0 1,927 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,184 May-07-2021, 03:26 PM
Last Post: herwin

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020