将文件移到FTP上的父文件夹 [英] Move file to parent folder on FTP

查看:130
本文介绍了将文件移到FTP上的父文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我以前在移动文件时遇到问题,与绝对路径和相对路径有关 RenameTo 属性。我目前得到了553错误(文件名不允许)。



文件位于// blah / John / Update / Done /,我想移动到//../ Update /。



以下是我正在使用的代码片段:

  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 属性到绝对路径,它仍然给我同样的错误。

解决方案

我不认为 ... 在相对路径中有效。
您可能意思是:
$ b

  requestMove.RenameTo =./../ + fileList [i] .fName; 
// ^ ^
//当前目录──┘│
//│
//上一个文件夹──┘

如果您当前的工作目录是 / blah / John / Update / Done / ./../ 有效地代表 / blah / John / Update



详细了解相对路径语法此处


I'm trying to move files from a folder into it's parent folder.

I had issues moving files before, something to do with absolute versus relative path on the RenameTo property. I'm currently getting a 553 error(file name not allowed).

Files are in "//blah/John/Update/Done/" and I'd like to move to "//../Update/".

Here is a snippet of the code I'm using:

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();
}

I've tried changing the RenameTo property to the absolute path and it still gives me the same error.

解决方案

I don't think ... is valid in relative paths. You probably meant:

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

If your current working directory is /blah/John/Update/Done/, ./../ effectively represents /blah/John/Update.

More about relative path syntax here.

这篇关于将文件移到FTP上的父文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆