使用 reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory; 
如果存在相同文件夹会报错是吗?怎样判断是否存在同名文件夹呢?

解决方案 »

  1.   

    还有 如果是 /a/b/c 这样的路径,会报错,怎么解决呢?
      

  2.   

    C#操作FTP的相关代码,搜一下,不是一大堆吗?
    找不到相应的解决办法?
      

  3.   

    先判断文件夹是否存在
    Directory.Exists("///")
      

  4.   

    不知道楼主是要实现什么功能 
    如果最终目的是为了创建目录的话 (我的需求)我的做法是,不管目录文件夹是否存在 ,循环创建, 
    如果存在就会出异常,捕获,但不抛, 不存在的话就会创建.看看,有更好的方法发给我看看代码:             ...... 
            {
                ......            string serverPathURL1 = "ftp://" + fileStoreServerIP + ":" + fileStoreServerPort + "/" + this.UpSectionCB.Text;
                string serverPathURL2 = serverPathURL1  + "/" + this.UpFileGroupTB.Text.Trim();
                string serverPathURL3 = serverPathURL2 + "/" + this.UpFileTypeCB.Text;
                
                // 此例子中 this.UpSectionCB.Text,  this.UpFileGroupTB.Text.Trim() , 
                // this.UpFileTypeCB.Text  都表示 文件夹 名称
                  // fileStoreServerIP ,fileStoreServerPort 表示ftp服务器IP , 端口            UpMakeDirectory(serverPathURL1);
                UpMakeDirectory(serverPathURL2);
                UpMakeDirectory(serverPathURL3);            ......
            }        /// <summary>
            /// 创建文件路径
             /// </summary>
            /// <param name="uploadUrl">创建的路径</param>
            public void UpMakeDirectory(string uploadUrl)
            {
                FtpWebResponse uploadResponse = null;
                try
                {
                    FtpWebRequest uploadRequest =
                        (FtpWebRequest)WebRequest.Create(new Uri(uploadUrl));
                    uploadRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
                    uploadRequest.Proxy = null;               
                    uploadResponse =
                        (FtpWebResponse)uploadRequest.GetResponse();
                }
                catch
                {
                    if (uploadResponse != null)
                    {
                        uploadResponse.Close();
                    }
                }
                if (uploadResponse != null)
                {
                    uploadResponse.Close();
                }
            }
      

  5.   

    ftp好像没有现成的判断文件夹是否存在的命令
    我是用获取文件列表,然后遍历是否相同来实现的
      

  6.   

    哎,我用的try catch捕捉错误,出错了继续循环创建,就是感觉有点小慢,没办法了,笨方法,呵呵。