Python Forum
Reading txt files in ssh server.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading txt files in ssh server.
#1
Connected to my SSH server with paramiko. I can write files to there remotely. But can't read any txt files from there. Can i read data from txt file?
Reply
#2
Of course you can parse the contents of a text file... simplest example:

file1 = open("MyFile.txt","r") 
file1.readlines()
file1.close()
you can do all sorts of stuff reading and writing to text files.
Reply
#3
That doesn't help since the files are on a remote machine.

I just had a quick look at the Paramiko docs and there's an SFTP client, so you should investigate using that.
Reply
#4
(Aug-06-2020, 04:22 AM)t4keheart Wrote: Of course you can parse the contents of a text file... simplest example:

file1 = open("MyFile.txt","r") 
file1.readlines()
file1.close()
you can do all sorts of stuff reading and writing to text files.

i know this bro but this only reads your computers files. You can't read a txt from remote server with that.
But i found my own way:

readTxt= transport.open_session()
        readTxt.exec_command(cd server;cat example.txt)
        data = readTx.recv(1024)
But when you try to print data, the output is: 'b' hello world \n or something like that i dont remember.
So you need to decode and strip it.
readTxt= transport.open_session()
        readTxt.exec_command(cd server;cat example.txt)
        data = readTx.recv(1024)
        newData = data.decode().rstrip()
And now the output is just "hello world"
Reply
#5
Did you also look at the SFTP client?
Reply
#6
(Aug-06-2020, 04:54 AM)ndc85430 Wrote: Did you also look at the SFTP client?
i dont remember if you know that can you tell me? This method has some bugs.
Reply
#7
As I hinted, see the docs.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to take the tar backup files form remote server to local server sivareddy 0 1,892 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Reading Multiple text Files in pyhton Fatim 1 1,911 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  Trouble reading files using pyexcel codebeacon 2 2,175 Feb-08-2021, 05:53 AM
Last Post: codebeacon
  How to stop the reading of files Laplace12 4 2,349 Jul-27-2020, 04:07 PM
Last Post: Gribouillis
  How can I speed up my openpyxl program reading Excel .xlsx files? deac33 0 3,383 May-04-2020, 08:02 PM
Last Post: deac33
  Other modules for reading audio files? jedzz 0 1,592 Mar-25-2020, 11:07 PM
Last Post: jedzz
  Error With Reading Files In Directory And Calculating Values chascp 2 2,417 Feb-15-2020, 01:57 PM
Last Post: chascp
  transfering files between server locations using ftplib katesfb 1 1,981 Nov-11-2019, 12:24 AM
Last Post: katesfb
  Reading DBF files from Amazon s3 throwing error - 'int' object has no attribute 'isa abeesm 1 2,904 Sep-22-2019, 05:49 PM
Last Post: ndc85430
  Reading and writing files JakeHoward4 1 1,805 Aug-07-2019, 06:22 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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