[ https://issues.apache.org/jira/browse/CAMEL-12711?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16571267#comment-16571267 ]
ASF GitHub Bot commented on CAMEL-12711: ---------------------------------------- davsclaus commented on a change in pull request #2452: [CAMEL-12711] Add configuration property 'bindAddress' for SFTP URL: https://github.com/apache/camel/pull/2452#discussion_r208142504 ########## File path: components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java ########## @@ -1074,4 +1099,64 @@ public synchronized boolean sendSiteCommand(String command) throws GenericFileOp // is not implemented return true; } + + /* + * adapted from com.jcraft.jsch.Util.createSocket(String, int, int) + * + * added possibility to specify the address of the local network interface, against the + * connection should bind + */ + static Socket createSocketUtil(final String host, final int port, final String bindAddress, final int timeout) { + Socket socket = null; + if (timeout == 0) { + try { + socket = new Socket(InetAddress.getByName(host), port, InetAddress.getByName(bindAddress), 0); + return socket; + } catch (Exception e) { + String message = e.toString(); + if (e instanceof Throwable) { + throw new RuntimeCamelException(message, (Throwable)e); + } + throw new RuntimeCamelException(message); + } + } + final Socket[] sockp = new Socket[1]; + final Exception[] ee = new Exception[1]; + String message = ""; + Thread tmp = new Thread(new Runnable() { + public void run() { + sockp[0] = null; + try { + sockp[0] = new Socket(InetAddress.getByName(host), port, InetAddress.getByName(bindAddress), 0); + } catch (Exception e) { + ee[0] = e; + if (sockp[0] != null && sockp[0].isConnected()) { + try { + sockp[0].close(); + } catch (Exception eee) { } + } + sockp[0] = null; + } + } + }); + tmp.setName("Opening Socket " + host); + tmp.start(); + try { + tmp.join(timeout); + message = "timeout: "; + } catch (java.lang.InterruptedException eee) { + } + if (sockp[0] != null && sockp[0].isConnected()) { + socket = sockp[0]; + } else { + message += "socket is not established"; + if (ee[0] != null) { + message = ee[0].toString(); + } + tmp.interrupt(); + tmp = null; + throw new RuntimeCamelException(message, ee[0]); Review comment: Should this not be IOException and then let the method have throws IOException ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > SFTP: Cannot specify bind address of local network interface > ------------------------------------------------------------ > > Key: CAMEL-12711 > URL: https://issues.apache.org/jira/browse/CAMEL-12711 > Project: Camel > Issue Type: Bug > Components: camel-ftp > Affects Versions: 2.22.0 > Reporter: Felix Feisst > Priority: Major > > In an environment with multiple network interfaces, it might be necessary to > specify the address of the local interface, to which the SFTP connection > should bind. Unfortunately, this is not possible with the latest version of > camel-ftp. > > A new URI parameter 'bindAddress' should be introduces which can then be set > to the IP-Address of the local network interface against which the SFTP > connection should bind. -- This message was sent by Atlassian JIRA (v7.6.3#76005)