C#应用程序中的FTP代理问题 [英] FTP proxy problem in C# application

查看:64
本文介绍了C#应用程序中的FTP代理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void Upload(string filename)
        {
            string ftpHost = ftpServerIP;
            //here correct hostname or IP of the ftp server to be given  
            FileInfo fileInf = new FileInfo(filename);
            string ftpFullPath = "ftp://" + ftpHost + fileInf.Name;
            MessageBox.Show(ftpFullPath);
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpFullPath);
            ftp.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            //userid and password for the ftp server to given  
            ftp.KeepAlive = true;
            ftp.UseBinary = true;
            ftp.Method = WebRequestMethods.Ftp.UploadFile;
            FileStream fs = File.OpenRead(filename);
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();
            Stream ftpStream = ftp.GetRequestStream();
            ftpStream.Write(buffer, 0, buffer.Length);
}



[edit]添加了前置标记[/ediit]

当我分配代理时会给出异常
ftp.Proxy = new System.Net.WebProxy("http://10.16.5.39:3128/",true);
使用HTTP代理时不支持所请求的FTP命令."
当我设置ftp.Proxy = null;它给出了异常
无法连接到远程服务器"



[edit]Added pre tag[/ediit]

When I assign proxy it gives the exception
ftp.Proxy = new System.Net.WebProxy("http://10.16.5.39:3128/", true);
"The requested FTP command is not supported when using HTTP proxy."
When I set ftp.Proxy = null; it gives the exception
"Unable to connect to the remote server"
Help me to solve the issue.

推荐答案

亲爱的朋友,

Thee是 FtpWebRequest的属性.只需使用一个空实例对其进行初始化...

Dear Friend,

Thee is a property for a FtpWebRequest. Just initialize it with an empty instance...

myFtpRequestObj.Proxy = new WebProxy();



该问题可以使用
解决



The problem can be solved using

request.Proxy = nothing


这篇关于C#应用程序中的FTP代理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆