Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paramiko, appending file on SSH server

I'm writing a class which communicates with a text file on a remote SSH server (sitting on a windows machine) using the paramiko library. I have the following line in my python app (sitting on a linux machine) which should establish a connection for appending a file;

file(pollFile, mode='a', bufsize=1)

But how do I actually go about interacting with this file I've established a conneciton with?

Thanks!

like image 474
Mark Corrigan Avatar asked Apr 08 '26 19:04

Mark Corrigan


1 Answers

The object returned from the file call is a paramiko.SFTPFile handle, which can be interacted with using write, writelines e.g.

data = "Hello World"
file_hande = sftp_client.file(pollFile, mode='a', bufsize=1)
file_handle.write(data)
file_handle.flush()
file_handle.close()
like image 182
Petesh Avatar answered Apr 10 '26 08:04

Petesh