FtpWebRequest抛出System.Net.WebException:远程服务器返回错误:(530)未登录

时间:2015-11-25 16:41:13

标签: c# .net ftpwebrequest

我有一个试图在我的FTP服务器上创建文件夹的Windows服务。该服务在本地运行良好,完全没有问题。当我尝试在服务器上执行但是我得到了530.真奇怪的是我创建了一个运行相同代码的小.aspx页面并且它可以工作。它只在我的服务代码中失败。

            var ftpLocation = ConfigurationManager.AppSettings["FtpLocation"];
        var ftpUserName = ConfigurationManager.AppSettings["FtpUserName"];
        var ftpPassword = ConfigurationManager.AppSettings["FtpPassword"];

        var request = (FtpWebRequest)WebRequest.Create(ftpLocation);
        request.Method = WebRequestMethods.Ftp.MakeDirectory;
        request.EnableSsl = true;
        request.Credentials = new NetworkCredential(ftpUserName, ftpPassword);
        try
        {
            logger.Debug("Calling MakeDirectory for " + ftpPath);

            using (var response = (FtpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != FtpStatusCode.PathnameCreated)
                    throw new ApplicationException(string.Format("FTP failed with the following response: {0} - {1}",
                        response.StatusCode, response.StatusDescription));
                response.Close();
            }
            logger.Debug("Calling MakeDirectory for " + ftpPath);

        }

我还应该注意我正在尝试创建的目录中有一个空格,但它再次在我的aspx页面上100%正确。

1 个答案:

答案 0 :(得分:0)

啊!我至少看了十几次密码。在部署

时,我们的部署服务器将替换密码中的3个字符