Aug-04-2020, 01:37 PM
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?
Reading txt files in ssh server.
|
Aug-04-2020, 01:37 PM
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?
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.
Aug-06-2020, 04:41 AM
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.
Aug-06-2020, 04:51 AM
(This post was last modified: Aug-06-2020, 04:51 AM by therenaydin.)
(Aug-06-2020, 04:22 AM)t4keheart Wrote: Of course you can parse the contents of a text file... simplest example: 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"
Aug-06-2020, 04:54 AM
Did you also look at the SFTP client?
Aug-06-2020, 05:04 AM
|
|