【问题标题】:unable to connect to the remote server - GoDaddy upload无法连接到远程服务器 - GoDaddy 上传
【发布时间】:2016-11-02 17:59:12
【问题描述】:

我在向 GoDaddy 的 FTP 服务器上传一些位图时(随机)收到此错误: “无法连接到远程服务器”

这是我的代码:

  public static string UploadFileToFTP(byte[] image, string targetpath, string source, string imgName)
    {

        string ftpurl = ConfigurationManager.AppSettings["Ftp_Images_Domain"];
        string ftpusername = ConfigurationManager.AppSettings["Ftp_Images_Usr"];
        string ftppassword = ConfigurationManager.AppSettings["Ftp_Images_Pwd"];

        try
        {
            SetMethodRequiresCWD();

            string ftpfullpath = ftpurl + targetpath + source;

            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
            ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
            ftp.KeepAlive = false;
            ftp.UseBinary = true;
            ftp.Method = WebRequestMethods.Ftp.UploadFile;

            using (Stream ftpstream = ftp.GetRequestStream())
            {

                ftpstream.Write(image, 0, image.Length);
                //image.InputStream.CopyTo(ftpstream);
            }
            return "Success";
        }
        catch (WebException e)
        {
            String status = ((FtpWebResponse)e.Response).StatusDescription;
            logger.Error(e);
            return status;
        }
    }

这一切突然发生,原因不明。当然,托管公司也没有好的答案:) 对于那些遇到这种情况的人,我所做的是:

  1. 创建了另一个新的 FTP 帐户
  2. 为 FTP 帐户授予读/写权限

这解决了问题。

祝你好运

【问题讨论】:

    标签: ftp upload


    【解决方案1】:
    1. 创建另一个新的 FTP 帐户
    2. 为 FTP 帐户授予读/写权限

    这可以解决问题。

    【讨论】: