【问题标题】:FTP - File name not allowed. (REMOTE SERVER ERROR 533) C# [duplicate]FTP - 不允许使用文件名。 (远程服务器错误 533)C# [重复]
【发布时间】:2020-05-28 18:55:05
【问题描述】:

我的应用很简单:

从 ftp 获取文件列表 - 步骤 1

循环每个项目并获取文件 - 步骤 2

将内容从 xml 文件写入数据库 - 步骤 3

在移动到循环中的另一个项目之前,让我们将处理过的文件移动到 另一个文件夹 - 第 4 步(错误)

这是我的代码(请阅读 cmets!):

if (ftpFiles.Any())
{
    foreach (var file in ftpFiles)
    {
        try
        {
            var item_path = $"ftp://my.url.ok:somePort/{item.FtpFolderName}/in/" + file;
            FtpWebRequest xml_request = (FtpWebRequest)WebRequest.Create(item_path);
            xml_request.Method = WebRequestMethods.Ftp.DownloadFile;
            xml_request.Credentials = new NetworkCredential("username", "password");

            using (FtpWebResponse xml_response = (FtpWebResponse)xml_request.GetResponse())
            {
                using (StreamReader xml_reader = new StreamReader(xml_response.GetResponseStream()))
                {
                    // PROCESSING XML FILE AND MAKING DATABASE CALL TO INSERT VALUE TO DB AND THAT IS FINE!
                }
            }


            // BEFORE I MOVE TO ANOTHER FILE IN LOOP I WANT TO MOVE PREVIOUS FILE TO ANOTHER FOLDER

            var item_to_move_original_path = $"ftp://my.url.ok:somePort/{item.FtpFolderName}/in/" + file;
            var item_to_move_new_path = $"ftp://my.url.ok:somePort/{item.FtpFolderName}/processed/" + file;

            FtpWebRequest xml_request_rename = (FtpWebRequest)WebRequest.Create(item_to_move_original_path);    
            xml_request_rename.Method = WebRequestMethods.Ftp.Rename;

            xml_request_rename.Credentials = new NetworkCredential("username", "password");
            xml_request_rename.RenameTo = item_to_move_new_path;

            // IN LINE BELOW APP CRASHES AND IT SAYS THAT File name is not allowed

            // One more question here is can I use xml_request that I've created in a loop earlier to rename/move a file or I have to crate this
            // xml_request_rename
            FtpWebResponse response = (FtpWebResponse)xml_request_rename.GetResponse();

        }
        catch(Exception ex)
        {}
    }
}

【问题讨论】:

  • 您能否使用现有的 FTP 客户端(如 Filezilla)将文件上传到该位置?
  • @C.Evenhuis 是的。我正在使用 FileZilla,我可以毫无问题地写入该位置

标签: c# xml request ftp


【解决方案1】:

我已经能够通过更改此网址来解决此问题(删除部分网址):

var item_to_move_new_path = $"ftp://my.url.ok:somePort/{item.FtpFolderName}/processed/" + file;

到:

var item_to_move_new_path = $"/{item.FtpFolderName}/processed/" + file;

可能会注意到我删除了一个

ftp://my.url.ok:somePort/ 

从路径,一切正常,怎么会???

一切正常,但我不知道为什么,如果有人可以向我和其他正在观看此广告的人解释这一点,那就太棒了!

【讨论】:

    猜你喜欢
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多