How to select network interface when connecting to SFTP with JSch

前端 未结 3 1826
心在旅途
心在旅途 2021-01-14 15:33

I am facing problem to create a session to a remote SFTP server by JSch:

The command i use to connect the sftp server through shell is:



        
3条回答
  •  孤城傲影
    2021-01-14 16:05

    I do not think there's an explicit support for selecting a network interface to connect from in JSch.

    But you can implement a SocketFactory interface, such as that it creates a Socket instance using the constructor overload with the localAddr:

    public Socket(InetAddress address, int port, InetAddress localAddr, int localPort)
    

    (use 0 for the localPort)

    Then pass the factory to the Session.setSocketFactory() before calling the connect() and you should be good.

提交回复
热议问题