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);