抛出异常:
使用 HTTP 代理时不支持请求的 FTP 命令。

解决方案 »

  1.   


       #region 文件上传
            /// <summary>
            /// FTP方式将文件上传至服务器
            /// </summary>
            /// <param name="fileName">将要上传的文件</param>
            /// <param name="fileNewname">将要在服务器上保存的文件</param>
            internal static void Upload(string fileName, string fileNewname)
            {
                string strFileName = "";            // 获取文件的相关信息
                FileInfo fileInf = new FileInfo(fileName);
                if (fileNewname == "")
                {
                    strFileName = fileInf.Name;
                }
                else
                {
                    strFileName = fileNewname;
                }            // 根据uri创建FtpWebRequest对象 
                FtpWebRequest reqFTP;
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://10.10.10.110/" + strFileName));            // ftp用户名和密码
                //reqFTP.Credentials = new NetworkCredential("zhaoxp", "123456");            // 销毁到服务器的连接
                reqFTP.KeepAlive = true;
                // 获取或设置要发送到 FTP 服务器的命令。
                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
                // 传输文件的数据格式Binary
                reqFTP.UseBinary = true;
                // 文件是多大
                reqFTP.ContentLength = fileInf.Length;            // 缓冲大小设置为2kb
                int buffLength = 2048;
                byte[] buff = new byte[buffLength];
                int contentLen;            try
                {
                                    // 把文件读入到流中
                    FileStream fs = fileInf.OpenRead();
                    // 用于存储要012服务器的数据。
                    // 把文件流分装成小的字节数组,防止占用太多的服务器内存
                    contentLen = fs.Read(buff, 0, buffLength);
                    // 循环把文件流写入待发给ftp服务器的请求流中
                    while (contentLen != 0)
                    {
                        strm.Write(buff, 0, contentLen);
                        contentLen = fs.Read(buff, 0, buffLength);
                    }                fs.Close();
                    strm.Close();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message,"异常");
                }
            }
      

  2.   

    少了一句
    try内第一句为:Stream strm = reqFTP.GetRequestStream();
      

  3.   

    在这句的后面FtpWebRequest reqFTP;
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://10.10.10.110/" + strFileName));加上这两句:
    reqFTP .Method = WebRequestMethods.Ftp.ListDirectory;//发送一个请求命令
                    FtpWebResponse ftpResponse = (FtpWebResponse)reqFTP .GetResponse();//响应一个请求
      

  4.   

    --如果你使用FTP via SSL,可以使用HTTP代理
    --request.Proxy = new WebProxy("http://myproxy"); // 使用HTTP代理
    --request.EnableSSL = true; // 使用SSL通道和FTP通讯
    --这个方法基本上只对下载文件有效。如果你要用IE设置里面的FTP代理的话,你需要明确指定一个空的代理
    --request.Proxy = GlobalProxySelection.GetEmptyWebProxy()
    我使用的是FTP via SSL,现在要上传文件,怎么办
      

  5.   

    楼主解决了吗?
    我也遇到了这样的问题呀我的这个问题是
    如果IE设置了浏览器代理就没法上传了
    怎样才能在IE设置了代理的情况下也能上传呢?