views:

85

answers:

1

How can i get a file from remote computer? i know remote computer ip and 51124 port is open. i need this algorith:(

this is a Windows Application visual studio 2008

)

1) Connect 192.xxx.x.xxx ip via 51124 port
2) filename:123456 (i want to search it on remote machine)
3) Get File
4) Save C:\

51124 port is open. can i access and can i search any file according to filename? My code is below:


IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, 51124);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
sock.Bind(ipEnd);
sock.Listen(maxConnections);
Socket serverSocket = sock.Accept();
byte[] data = new byte[bufferSize];
int received = serverSocket.Receive(data);
int filenameLength = BitConverter.ToInt32(data, 0);
string filename = Encoding.ASCII.GetString(data, 4, filenameLength);
BinaryWriter bWrite = new BinaryWriter(File.Open(outPath + filename, FileMode.Create));
bWrite.Write(data, filenameLength + 4, received - filenameLength - 4);
int received2 = serverSocket.Receive(data);
while (received2 > 0) {
    bWrite.Write(data, 0, received2);
    received2 = serverSocket.Receive(data);
}
bWrite.Close();
serverSocket.Close();
sock.Close();

MyQuery(targetip, port, filename)

i can use it like that: MyQuery(192.xxx.x.xxx,51124,"MyNeddedFile");


MyQuery(targetip, port, filename)
{

.....
...
..
.


}
+4  A: 

You have been trying to ask this question a few times now - perhaps this explains why we cannot answer your question:

If you have an FTP server, it will (by default) listen on port 21. So if I send a message according to the FTP protocol to port 21, it will respond.

If I have apache or IIS (or some other webserver) listening on for instance port 80, and I send an FTP message to it, it will give me an error, because they are expecting HTTP requests.

Without knowing what application is listening on port 51124, we can't possibly tell you how to talk to it.

deltreme
i try to make a windows application via visual Studio:)
programmerist
If you're making both the server and the client, i advise you to chop the problem in pieces. For instance, first make a server application that receives data and just returns it, then make a client application that connects to the server, sends data, and receives the response. This way, if you run into a problem, you can ask more specific questions which we are happy to help you with. Once you have a working client and server, you can extend the client to actually request file names and the server to search for those files.
deltreme