FTP file from a remote server

  • Thread starter Thread starter Lalasa
  • Start date Start date
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.
 
Further clarification -
Dns.Resolve resolves the ip address, provided the hostname. How do I do
if I want to connect to a ftp site like ftp://ftp.xyz.ab.org

Thanks,
Lalasa.
 
Back
Top