FtpWebRequest throws System.Net.WebException: The remote server returned an error: (530) Not logged in

FtpWebRequest throws System.Net.WebException: The remote server returned an error: (530) Not logged in

我有一个 windows 服务试图在我的 FTP 服务器上创建一个文件夹。该服务在本地运行良好,完全没有问题。但是,当我尝试在服务器上执行时,我得到了 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);

        }

我还应注意,我尝试创建的目录中有一个 space,但它在我的 aspx 页面上同样 100% 正确。

呃!我至少看了十几遍密码。原来我们的部署服务器在部署时正在替换密码中的 3 个字符