简体   繁体   English

当传入代理的请求超过 http 时,如何从 ftp 代理返回 ftp 响应?

[英]How to return ftp response from ftp proxy, when request incoming to proxy is over http?

At start thank you all for your kind help, Every hint is great and can teach me a lot, I appreciate every comment.在开始时感谢大家的帮助,每一个提示都很棒,可以教会我很多东西,我感谢每一个评论。 Before you respond I'm aware that there is a lot of working solutions and working ftp proxies, but I'm asking this question for learning purposes and I try to understand how it works.在您回复之前,我知道有很多有效的解决方案和有效的 ftp 代理,但我问这个问题是为了学习,我试图了解它是如何工作的。

I have to implement my own ftp proxy server to capture ftp commands.我必须实现自己的 ftp 代理服务器来捕获 ftp 命令。 The issue is that request incoming to proxy from client is over http protocol and when I return raw ftp response from ftp server through proxy to the client, then client browser is not able to handle this response as ftp response. The issue is that request incoming to proxy from client is over http protocol and when I return raw ftp response from ftp server through proxy to the client, then client browser is not able to handle this response as ftp response. Currently I'm trying to hardcode initial response from ftp proxy as following:目前我正在尝试对来自 ftp 代理的初始响应进行硬编码,如下所示:

var clientWriter = new BinaryWriter(clientNetStream);
clientWriter.Write("220 (vsFTPd 3.0.3)\r\n");

But when client browser got this response, then it is showing following box: https://imgur.com/XcIy7Rw但是当客户端浏览器收到此响应时,它会显示以下框: https://imgur.com/XcIy7Rw

Because above does not work then I've tried to include ftp response in HttpResponse as follows:因为上面不起作用,所以我尝试在 HttpResponse 中包含 ftp 响应,如下所示:

var clientWriter = new BinaryWriter(clientNetStream);
                        clientWriter.Write(
                            "HTTP/1.1 200 OK\r\n" +
                            "Date: Mon, 19 Jul 2004 16:18:20 GMT\r\n" +
                            "Server: Apache\r\n" +
                            "Last-Modified: Sat, 10 Jul 2004 17:29:19 GMT\r\n" +
                            "Accept-Ranges: bytes\r\n" +
                            "Content-Length: 9328\r\n" +
                            "Connection: keep-alive\r\n" +
                            "Content-Type: text/html\r\n" +
                            "\r\n" +
                            "220 (vsFTPd 3.0.3))\r\n");

But then browser handle this as follows: https://imgur.com/JuFTjs7但随后浏览器按如下方式处理: https://imgur.com/JuFTjs7

What I try do to is return "220 (vsFTPd 3.0.3)\r\n" response from server to the client and then I expect that client will send "USER anonymous\r\n" command to log in, but with both solutions this is not happening.我尝试做的是从服务器向客户端返回“220 (vsFTPd 3.0.3)\r\n”响应,然后我希望客户端将发送“USER anonymous\r\n”命令登录,但两者都有解决方案这不会发生。 I try to make working following sequence automatically (please see Wireshark screenshot).我尝试自动按照顺序进行工作(请参阅 Wireshark 屏幕截图)。 https://imgur.com/yT3dRxW https://imgur.com/yT3dRxW

Does anybody knows how to return response from server to the client, to make client to communicate with ftp server?有谁知道如何从服务器返回响应给客户端,使客户端与 ftp 服务器通信?

If client send http request to the proxy then can I return Ftp response instead of http response?如果客户端向代理发送 http 请求,那么我可以返回 Ftp 响应而不是 http 响应吗? If not, then how proxy response should looks like?如果不是,那么代理响应应该是什么样子?

It is important to distinguish between a HTTP Proxy and a FTP proxy.区分HTTP代理和FTP代理非常重要。 A HTTP proxy is typically capably to handle URLs starting with http(s):// and ftp:// . HTTP 代理通常能够处理以http(s)://ftp://开头的 URL。 For URLs starting with ftp:// , the proxy does a protocol transformation.对于以ftp://开头的 URL,代理会进行协议转换。

That means that the client uses the HTTP protocol to transmit the URL to the proxy (in this case starting with ftp:// ).这意味着客户端使用HTTP协议将 URL 传输到代理(在这种情况下从ftp://开始)。 Due to the URL starts with ftp:// , the proxy knows that it must use the FTP protocol to connect to the server.由于 URL 以ftp://开头,代理知道它必须使用FTP协议来连接服务器。 This is referred to as FTP over HTTP as the client is connecting to a FTP server using a HTTP client.这被称为FTP over HTTP ,因为客户端正在使用 Z29DC869EA246FF789 客户端连接到 FTP 服务器。

Alternatively, the client can use a native FTP client to connect to the server using the proxy.或者,客户端可以使用本机 FTP 客户端使用代理连接到服务器。 In this case, the client uses the FTP protocol to talk to the proxy and the proxy uses the FTP protocol to talk to the server.在这种情况下,客户端使用FTP协议与代理通信,代理使用FTP协议与服务器通信。 This is referred to as native FTP proxy .这被称为native FTP proxy

As you already noticed, in the FTPoverHTTP scenario, the client does not follow up on any FTP response.正如您已经注意到的,在FTPoverHTTP场景中,客户端不会跟进任何FTP响应。 Instead, you have to implement the protocol transformation in the proxy accordingly.相反,您必须相应地在代理中实现协议转换。 Pass the username and password from client to proxy as follows: ftp://username:password@server.com .将用户名和密码从客户端传递给代理,如下所示: ftp://username:password@server.com Your proxy must extract the credentials from the URL, connect to the server, and then issue the USER and PASS command on behalf of the client.您的代理必须从 URL 中提取凭据,连接到服务器,然后代表客户端发出USERPASS命令。

Hint: The proxy also needs to extract directory/filenames from the URL in order to get a directory listing / file content using the FTP protocol from the server, then present it to the client accordingly, eg directory listing as html page with links to the artifacts in the directory or in case a file has been accessed, send a response which triggers a HTTP file download on the client提示:代理还需要从 URL 中提取目录/文件名,以便使用FTP协议从服务器获取目录列表/文件内容,然后将其相应地呈现给客户端,例如目录列表为 ZFC335EZ83 页面,其中包含指向 68 个 FC69D52 的链接目录中的工件或在文件已被访问的情况下,发送响应以触发客户端上的HTTP文件下载

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

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