Binding SFTP Client to Single IP Address on local machine

+1 vote
asked May 10, 2012 by eugene_iveri_com (160 points)
edited Jul 12, 2012

If you are on a machine with multiple IP addresses configured. Can you setup REBEX SFTP to bind to only one of those addresses. as the remote server that you are ftp'ing to allows only a connection from one of the configured IP's from your side.

Applies to: Rebex SFTP

1 Answer

0 votes
answered May 10, 2012 by Lukas Pokorny (123,810 points)
edited Jul 12, 2012
 
Best answer

By default, Windows TCP/IP stack will choose a local address to bind to according to the local routing table, so it is not normally needed to select it manually.

If you need to override this behavior, a bit of additional work is required - you have to supply a custom Rebex.Net.ISocket implementation that is capable of binding to a specified IP and instruct Rebex SFTP to use it by calling the Sftp object's SetSocketFactory method prior to connecting (the same applies to other Rebex components).

To get started, download the sample ISocket implementation and give it a try. (The code is in C# - if you would like to have a VB.NET version instead, please let us know and we will convert it for you.) Using it from your application to bind to a specific local IP is simple. For example, to bind to the local loopback interface, do this:

using Rebex.Net;
using System.Net;
...

Sftp sftp = new Sftp();
sftp.SetSocketFactory(SimpleSocket.GetFactory(IPAddress.Parse("127.0.0.1")));
sftp.Connect(hostname);
...