Write to file in sftp without transfer the file

Viewed 1012

I'm looking for a way to write in a file in sftp without transfer the file. I work with jsch and i saw that with chilkat there was a way to do this :

CkSFtp sftp = new CkSFtp();
sftp.WriteFileText(handle, "ansi", "Hey !");
sftp.CloseHandle(handle);

but with jsch i still haven't figured out a way to do it. And I couldn't get the chilkat library to work.

So, do you have solutions ?

1 Answers

I assume you want to upload in-memory data/text. JSch has loads of methods can upload in-memory data.

The basic one is:

public void put(InputStream src, String dst) throws SftpException

To upload text string using the above method, you can use:

InputStream src = new ByteArrayInputStream("Hey !".getBytes(StandardCharsets.UTF_8));
sftp.put(src, "/remote/path/file.txt");

The other options is:

public OutputStream put(String dst) throws SftpException

Regarding your wording: As @RealSkeptic already commented, you always transfer the same data, no matter if the source is a file or not. So you cannot upload without "transfer". The SFTP protocol nor the server do not care where you take the data from.

Related