Mark Corrigan
Mark Corrigan

Reputation: 544

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!

Upvotes: 2

Views: 2230

Answers (1)

Anya Shenanigans
Anya Shenanigans

Reputation: 94634

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()

Upvotes: 3

Related Questions