==ftp通过代理下载文件问题==

ChinaOneCup ChinaOneCup 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
A机:内网 不能直接访问C机,需要设置代理通过B机连接C机
B机:内网 安装CCProxy代理工具,可以直接C机
C机:外网 安装有FTP服务

在A机用flashfxp可以访问C机的FTP服务,如下是我的代码
在A机无法访问C机的FTP服务,在B机可以访问C机的FTP服务

我的问题是如何在A机能通过代理也能访问C机的FTP服务
  private int DownloadFtp()
{
FtpWebRequest reqFTP;
try
{
FileStream outputStream = new FileStream("c:\a.txt", FileMode.Create);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://211.103.99.xx/a.txt"));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.KeepAlive = false;

WebProxy proxy = WebProxy.GetDefaultProxy();//获取默认代理
if (proxy != null)//如果使用了代理
{
reqFTP.Proxy = proxy;
}

reqFTP.Credentials = new NetworkCredential("test", "123456");

FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
return 0;
}
catch
{
return -1;
}
}

...全文
评论
收藏 已收藏
分享
返回顶部
ChinaOneCup
C# 111,128 成员 642,536 内容