【问题标题】:Move file to parent folder on FTP将文件移动到 FTP 上的父文件夹
【发布时间】:2015-06-17 18:30:30
【问题描述】:

我正在尝试将文件从文件夹移动到其父文件夹。

我之前在移动文件时遇到过问题,这与 RenameTo 属性上的绝对路径与相对路径有关。我目前收到 553 错误(不允许使用文件名)。

文件位于“//blah/John/Update/Done/”中,我想移至“//../Update/”。

这是我正在使用的代码的 sn-p:

string ftpConn="ftp://blah/John/Update/";
for (int i = 0; i < fileList.Count; i++ )
{
    var requestMove = (FtpWebRequest)WebRequest.Create(ftpConn + "Done/" + fileList[i].fName);
    requestMove.Method = WebRequestMethods.Ftp.Rename;
    requestMove.Credentials = new NetworkCredential(ftpUser, ftpPass);                   
    requestMove.RenameTo = ".../John/Update/" + fileList[i].fName;
    requestMove.GetResponse();
}

我尝试将RenameTo 属性更改为绝对路径,但仍然出现同样的错误。

【问题讨论】:

  • 我不太清楚你所说的... 是什么意思。尝试"./../" + fileList[i].fName,如果当前目录为/blah/John/Update/Done,则扩展为"/blah/John/Update/" + fileList[i].fName
  • @cubrr 成功了!你想把它作为获得荣誉的答案吗?

标签: c# ftp


【解决方案1】:

我认为... 在相对路径中无效。 您可能的意思是:

requestMove.RenameTo = "./../" + fileList[i].fName;
//                      ^  ^
//        Current dir ──┘  │
//                         │
//      Go up one folder ──┘

如果你当前的工作目录是/blah/John/Update/Done/./../实际上代表/blah/John/Update

更多关于相对路径语法here

【讨论】:

  • 很高兴能帮上忙!如果您还有其他问题,请不要害怕询问。
猜你喜欢
  • 2021-08-02
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
  • 2022-11-14
  • 2016-05-03
  • 1970-01-01
  • 2018-10-16
相关资源
最近更新 更多