简体   繁体   English

FTP通过FTP代理

[英]FTP through FTP proxy

I am trying to download a file using FTP through a FTP proxy (on my side). 我试图通过FTP代理(在我这边)使用FTP下载文件。 This is script I am trying to implement in C#: 这是我试图在C#中实现的脚本:

On Commandline:
ftp -i -s:get.ini CORPORATE_PROXY.com  
-----------get.ini------------
CORPORATE_PROXY_USER@CLIENT_FTP.com abc/user_name
CORPORATE_PROXY_PASSWORD 
user_name_password
cd pub/linux/knoppix
get packages.txt
bye
-----------get.ini------------

abc/user_name is my user name who was granted by permissions to FTP through my corporate proxy. abc/user_name是我通过公司代理授予FTP权限的用户名。

I want to implement above script in C#, but after playing with many types of code found on Internet I cannot do that. 我想在C#中实现上面的脚本,但是在使用Internet上发现的许多类型的代码之后,我无法做到这一点。

FtpWebRequest request = FtpWebRequest.Create(new Uri(@"ftp://" + CORPORATE_PROXY.com + @"/" + Path.GetFileName(fileToUpload))) as FtpWebRequest;
request.UseBinary = true;
request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.UploadFile;
if (!string.IsNullOrEmpty(CORPORATE_PROXY_USER) && !string.IsNullOrEmpty(CORPORATE_PROXY_PASSWORD ))
    request.Credentials = new NetworkCredential(CORPORATE_PROXY_USER, CORPORATE_PROXY_PASSWORD );

//Get physical file
FileInfo fi = new FileInfo(fileToUpload);
Byte[] contents = new Byte[fi.Length];

//Read file
FileStream fs = fi.OpenRead();
fs.Read(contents, 0, Convert.ToInt32(fi.Length));
fs.Close();

request.Proxy = new WebProxy("CLIENT_FTP.com");
request.Proxy.Credentials = new NetworkCredential(abc/user_name, user_name_password);

//Write file contents to FTP server
Stream rs = request.GetRequestStream();
rs.Write(contents, 0, Convert.ToInt32(fi.Length));
rs.Close();

FtpWebResponse response = request.GetResponse() as FtpWebResponse;
string statusDescription = response.StatusDescription;
response.Close();
return statusDescription;

The main problem is that for the proxy I am using WebProxy, while I suspect I should use FTPProxy - which I cannot find anythere? 主要的问题是,对于代理我使用WebProxy,而我怀疑我应该使用FTPProxy - 我找不到任何东西? Any ideas which direction should I go, or maybe WebProxy is fine? 我应该去哪个方向,或者WebProxy可以吗?

Try using WebRequest instead of FtpWebRequest in your code example. 尝试在代码示例中使用WebRequest而不是FtpWebRequest

By doing so, the connection from client to proxy can be HTTP whereas the connection from proxy to destination server is FTP. 通过这样做,从客户端到代理的连接可以是HTTP,而从代理到目标服务器的连接是FTP。 The proxy will handle the protocol translation, this technique is referred to as FTP over HTTP. 代理将处理协议转换,这种技术称为FTP over HTTP。

It is also possible to use a native FTP Proxy where client to proxy and proxy to server connections are FTP. 也可以使用本机FTP代理,其中客户端代理和代理服务器连接是FTP。 Make sure your proxy supports this. 确保您的代理支持此功能。

The proxy offers a separate proxy port to serve native FTP proxy connections. 代理提供单独的代理端口来提供本机FTP代理连接。

在过去,我使用Indy Project来通过FTP代理。

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

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