通过 FTP 代理进行 FTP

发布于 2025-01-07 04:37:52 字数 1685 浏览 0 评论 0原文

我正在尝试通过 FTP 代理(在我这边)使用 FTP 下载文件。 这是我尝试在 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 是我的用户名,通过我的公司代理授予 FTP 权限。

我想用 C# 实现上面的脚本,但是在尝试了在互联网上找到的多种类型的代码后我无法做到这一点。

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;

主要问题是,对于代理,我正在使用 WebProxy,而我怀疑我应该使用 FTPProxy - 我在那里找不到?有什么想法我应该朝哪个方向发展,或者 WebProxy 也可以吗?

I am trying to download a file using FTP through a FTP proxy (on my side).
This is script I am trying to implement in 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.

I want to implement above script in C#, but after playing with many types of code found on Internet I cannot do that.

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? Any ideas which direction should I go, or maybe WebProxy is fine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

篱下浅笙歌 2025-01-14 04:37:52

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

In the past I have used Indy Project to get through FTP proxies.

忘你却要生生世世 2025-01-14 04:37:52

尝试在代码示例中使用 WebRequest 而不是 FtpWebRequest

通过这样做,从客户端到代理的连接可以是 HTTP,而从代理到目标服务器的连接是 FTP。代理将处理协议转换,这种技术称为 FTP over HTTP。

还可以使用本机 FTP 代理,其中客户端到代理以及代理到服务器的连接都是 FTP。确保您的代理支持此功能。

该代理提供单独的代理端口来服务本机 FTP 代理连接。

Try using WebRequest instead of FtpWebRequest in your code example.

By doing so, the connection from client to proxy can be HTTP whereas the connection from proxy to destination server is FTP. The proxy will handle the protocol translation, this technique is referred to as FTP over HTTP.

It is also possible to use a native FTP Proxy where client to proxy and proxy to server connections are FTP. Make sure your proxy supports this.

The proxy offers a separate proxy port to serve native FTP proxy connections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文