简体   繁体   中英

How can i get a file from remote machine?

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,  ); 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) { ..... ... .. . } 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM