sshj icon indicating copy to clipboard operation
sshj copied to clipboard

How to read from the remote file into a Stream ?

Open saranya1988 opened this issue 6 years ago • 2 comments
trafficstars

Can anyone please help in reading a remote file into a Stream? I understand that I need to use something similar to this

sftpClient.get("/home/sftp/file1", new InMemoryDestFile() {
    @Override
    public OutputStream getOutputStream() throws IOException {						
	    return null;
    });

but any process on how exactly to do this would be helpful. Thanks in advance

saranya1988 avatar Sep 11 '19 11:09 saranya1988

To obtain an InputStream from a RemoteFile, you can do this:

RemoteFile f = sftpClient.getSFTPEngine().open("/home/sftp/file1");
InputStream is = f.new RemoteFileInputStream(0);

hierynomus avatar Feb 19 '20 09:02 hierynomus

I also have a question, how do I upload a file stream directly to a remote path without creating a new file locally to upload

wzd-hash avatar Jun 06 '23 03:06 wzd-hash