简体   繁体   English

我如何从远程计算机获取文件?

[英]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. 我知道远程计算机IP和51124端口已打开。 i need this algorith:( 我需要这个算法:(

this is a Windows Application visual studio 2008 这是Windows应用程序Visual Studio 2008

)

1) Connect 192.xxx.x.xxx ip via 51124 port 1)通过51124端口连接192.xxx.x.xxx IP
2) filename:123456 (i want to search it on remote machine) 2)文件名:123456(我想在远程计算机上搜索它)
3) Get File 3)获取文件
4) Save C:\\ 4)保存C:\\

51124 port is open. 51124端口已打开。 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) MyQuery(targetip,端口,文件名)

i can use it like that: MyQuery(192.xxx.x.xxx,51124,"MyNeddedFile"); 我可以这样使用: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. 如果您有FTP服务器,则它将(默认情况下)侦听端口21。因此,如果我根据FTP协议向端口21发送消息,它将响应。

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. 如果我有apache或IIS(或其他Web服务器)在侦听端口80,并且向它发送FTP消息,它将给我一个错误,因为他们期望HTTP请求。

Without knowing what application is listening on port 51124, we can't possibly tell you how to talk to it. 不知道哪个应用程序正在端口51124上侦听,我们可能无法告诉您如何与之交谈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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