L
Lalasa
Hi,
I wrote a FTP Client library and this is how I make a socket
connection. But this doesnt work for a remote ftp site. It fails at
Dns.Resolve. How do I make a socket connection for a remote ftp site?
private Socket ConnectSocket(string strRemoteServer, int strRemotePort)
{
Socket s = null;
IPHostEntry hostEntry = null;
try
{
// Get host related information.
hostEntry = Dns.Resolve(strRemoteServer);
// Loop through the AddressList to obtain the supported
AddressFamily. This is to avoid
// an exception that occurs when the host IP Address is not
compatible with the address family
// (typical in the IPv6 case).
foreach(IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, strRemotePort);
Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream,
ProtocolType.Tcp);
tempSocket.Connect(ipe);
if(tempSocket.Connected)
{
s = tempSocket;
break;
}
else
{
continue;
}
}
return s;
}
catch (Exception ex)
{
throw ex;
}
}
Thanks,
Lalasa.
I wrote a FTP Client library and this is how I make a socket
connection. But this doesnt work for a remote ftp site. It fails at
Dns.Resolve. How do I make a socket connection for a remote ftp site?
private Socket ConnectSocket(string strRemoteServer, int strRemotePort)
{
Socket s = null;
IPHostEntry hostEntry = null;
try
{
// Get host related information.
hostEntry = Dns.Resolve(strRemoteServer);
// Loop through the AddressList to obtain the supported
AddressFamily. This is to avoid
// an exception that occurs when the host IP Address is not
compatible with the address family
// (typical in the IPv6 case).
foreach(IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, strRemotePort);
Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream,
ProtocolType.Tcp);
tempSocket.Connect(ipe);
if(tempSocket.Connected)
{
s = tempSocket;
break;
}
else
{
continue;
}
}
return s;
}
catch (Exception ex)
{
throw ex;
}
}
Thanks,
Lalasa.