Search code examples
javagoogle-cloud-platformsftpjschgoogle-cloud-storage

transfer file from GCS bucket to SFTP server in java


I am able to read files from GCS bucket, but all the libraries like jsch which does file transfer to SFTP server look for a file path, instead of the file in memory. I don't want to write the file I read from GCS to a disk, How do I transfer the file in memory to SFTP?


Solution

  • I assume you want to upload in-memory data. JSch actually has loads of ChannelSftp.put methods overloads that can upload in-memory data.

    The basic one is with use of InputStream:

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

    The other options is with use of OutputStream:

    public OutputStream put(String dst) throws SftpException