Beispiel #1
0
        public static void deletePath(string pathName)
        {
            char[] chars = { '\r', '\n' };
            char[] slash = { '/' };
            Console.Out.WriteLine("pathName: " + HashUtils.getDirUri(pathName));
            var fileNames = listDir(pathName).Split(chars, StringSplitOptions.RemoveEmptyEntries);

            foreach (var fileName in fileNames)
            {
                //Console.Out.WriteLine("正在删除: "+fileName);
                Console.Out.WriteLine("FileName: " + fileName);


                deleteFile(fileName);
            }
            deleteDir(pathName);

            /*
             * //遍历文件夹获取所有文件的信息
             * var fileInfos = PathUtils.getFileInfos(pathName);
             * foreach (var fileInfo in fileInfos)
             * {
             *  deleteFile(fileInfo as FileInfo);
             * }'
             */
        }
Beispiel #2
0
 public static void deleteDir(string dirName)
 {
     try
     {
         string         uri      = HashUtils.getDirUri(dirName);
         var            request  = getFtpWebRequest(new Uri(uri), WebRequestMethods.Ftp.RemoveDirectory);
         FtpWebResponse response = (FtpWebResponse)request.GetResponse();
         response.Close();
         Console.Out.WriteLine(dirName + " 已删除");
     }
     catch (Exception ex)
     {
         Console.Out.WriteLine(dirName + " 删除失败");
     }
 }
Beispiel #3
0
        public static void setRemoteDir(string pathName)
        {
            string uri     = HashUtils.getDirUri(pathName);
            var    request = getFtpWebRequest(new Uri(uri), WebRequestMethods.Ftp.MakeDirectory);

            try
            {
                var response = request.GetResponse() as FtpWebResponse;
                return;
            }
            catch (Exception ex)
            {
                return;
            }
        }
Beispiel #4
0
        public static string listDir(string dirName)
        {
            try
            {
                string       uri            = HashUtils.getDirUri(dirName);
                var          request        = getFtpWebRequest(new Uri(uri), WebRequestMethods.Ftp.ListDirectory);
                var          response       = request.GetResponse();
                Stream       responseStream = response.GetResponseStream();
                StreamReader reader         = new StreamReader(responseStream);
                string       dirs           = reader.ReadToEnd();
                Console.Out.WriteLine(dirs);

                reader.Close();
                response.Close();
                return(dirs);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.Message);
            }
            return("");
        }