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

ChinaOneCup 2014-12-18 04:52:16
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;
}
}

...全文
73 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧