connecting to a shared drive on an external server

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a remote server that I need to connect to and this is the parameter
that will be passed to my program in C#...
"\\server_name\share$"

I tried sockets. The foll is the code that I give in...

remoteHost = "xxx.xx.com"; //actual name is entered in here
remotePort = 0; //since I do not have a port number

IPHostEntry hostEntry = Dns.Resolve(remoteHost);
foreach(IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipep = new IPEndPoint(address, remotePort);
clientSocket = new Socket(ipep.AddressFamily, SocketType.Stream,
ProtocolType.Tcp);
Console.WriteLine("Address {0}", Convert.ToString(address));
try
{
clientSocket.Connect(ipep);
}
catch(SocketException se)
{
Console.WriteLine("Code: {0}, Msg:
{1}",se.NativeErrorCode,se.Message );
}
}

Result--
It is able to resolve the netbios name to an ip address but since I do not
have the remote port number,
the error code is "10061" and the
error message is - "No connection could be made because the target machine
actively refused it."

Is there a way to get around giving the port number and simply connect using
the share name?

Thanks in advance
Jan
 
Thanks Michael,

I tried and the port at least listens. But how do I pass a user id and a
password since the server I am connecting to allows connections only from a
trusted source. When I run the program from my PC, my user id and pwd are
passed (I presume), but the server needs another one (which I have), but dont
know how to pass that from my program.

-Jan
 
Jan said:
I have a remote server that I need to connect to and this is the parameter
that will be passed to my program in C#...
"\\server_name\share$"

I tried sockets. The foll is the code that I give in...

remoteHost = "xxx.xx.com"; //actual name is entered in here
remotePort = 0; //since I do not have a port number

IPHostEntry hostEntry = Dns.Resolve(remoteHost);
foreach(IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipep = new IPEndPoint(address, remotePort);
clientSocket = new Socket(ipep.AddressFamily, SocketType.Stream,
ProtocolType.Tcp);
Console.WriteLine("Address {0}", Convert.ToString(address));
try
{
clientSocket.Connect(ipep);
}
catch(SocketException se)
{
Console.WriteLine("Code: {0}, Msg:
{1}",se.NativeErrorCode,se.Message );
}
}

Result--
It is able to resolve the netbios name to an ip address but since I do not
have the remote port number,
the error code is "10061" and the
error message is - "No connection could be made because the target machine
actively refused it."

Is there a way to get around giving the port number and simply connect
using
the share name?

Thanks in advance
Jan

You need to connect to .... to do doing what? The server path you are
showing is an SMB path so your client need to be an SMB client too, it makes
no sense trying to connect with an SMB server (port 139) using TCP/IP as
you won't implement the SMB protocol at the client do you?


Willy.
 
Back
Top