Search code examples
javaurlsftpjschgate

need URL for SFTP InputStream


I am writing an application that needs to connect via sftp to a GATE datastore that is living on a server. In order to open the datastore, I need to have the url for it. I am accessing the datastore through sftp and public/private key authorization with help of the Jsch class.

I can get to the data with ChannelSftp and then get an InputStream for the respective directory. I tried to get the path with sftp.getHome(), but that only gives me the relative path. In order to connect to the datastore, though, I need something like:

"sftp://path/to/datastore"

Is there a way to get the url of the sftp InputStream?

I know I could load the data from the InputStream to a local file, but I don't want to do that, because the datastore is huge. I also know that I can connect to sftp by putting username and password in the url, but I want to use a public key.


Solution

  • There's nothing like an SFTP URL.

    A decade ago there was an attempt to standardize an SFTP URL:
    https://datatracker.ietf.org/doc/html/draft-ietf-secsh-scp-sftp-ssh-uri-04

    And it was never completed and the proposal has expired years ago.


    So even if JSch could generate something like the SFTP URL (it cannot), you could not know if it works with the other system, as there's no common standard.

    You have to generate the URL yourself, conforming to the proprietary syntax of the target system.


    I've never seen any software that would somehow allow you to specify a private key in an SFTP URL.

    In general you can load the private key into some authentication agent that the system can read the key from.