FTP file from a remote server

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.
 
L

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top