任务需要一次性建多级子目录,如果需要一级一级建有点麻烦,不知道哪位仁兄能提供下方案或实现上述要求的,先谢了.

解决方案 »

  1.   

    可以去codeproject等网站搜下ftp的类库,这样你就不用去担心这些问题了。
      

  2.   

    应该有的,不过你可先做一个简单的程序试不就明白了。
    同时到codeproject上找找
      

  3.   

    你去找个ftpclient.cs的类用一用.里边提供了很多方法.封装的不错.
      

  4.   

    我不想调用未开源的类,而且那个我看过也没有我想要的.我现在需要判断一下目录是否存在,如不存在则建目录(可能多级),改了下面两个方法用了下,感觉还是很有问题,只能建一级目录不说,那个判断目录是否存在的第一次好用,第二次就不在根目录下判断而跳到下一级去了...
    /// 检查文件是否存在
            /// </summary>
            /// <param name="parentPath">父目录</param>
            /// <param name="name">文件名</param>
            /// <returns></returns>
            protected bool CheckFileOrPath(string parentPath, string fileName)
            {
                //检查一下日期目录是否存在
                FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(config.GetFtpUri(parentPath));
                req.Credentials = config.Credentials;
                req.Method = WebRequestMethods.Ftp.ListDirectoryDetails;            Stream stream = req.GetResponse().GetResponseStream();            using (StreamReader sr = new StreamReader(stream))
                {
                    string line = sr.ReadLine();
                    while (!string.IsNullOrEmpty(line))
                    {
                        GroupCollection gc = regexName.Match(line).Groups;
                        if (gc.Count != 1)
                        {
                            throw new ApplicationException("FTP 返回的字串格式不正确");
                        }                    string path = gc[0].Value;
                        if (path == fileName)
                        {
                            return true;
                        }                    line = sr.ReadLine();
                    }
                }            return false;        }        protected void CreatePath(string parentPath, string name)
            {
                FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(config.GetFtpUri(string.Format("{0}/{1}",parentPath,name)));
                req.Credentials = config.Credentials;
                req.Method = WebRequestMethods.Ftp.MakeDirectory;
                req.GetResponse();
            }
      

  5.   

    建目录本来就是一级一级的建立!
    baidu一下有很多FTP相关的