コード例 #1
0
        /// <summary>
        /// Get the sub directories and files of the Url. It will be used in enumerate
        /// all the folders.
        /// When run the FTP LIST protocol method to get a detailed listing of the files
        /// on an FTP server, the server will response many records of information. Each
        /// record represents a file.
        /// </summary>
        public IEnumerable <FTPFileSystem> GetSubDirectoriesAndFiles(Uri url)
        {
            FtpWebRequest request = WebRequest.Create(url) as FtpWebRequest;

            request.Credentials = this.Credentials;
            request.UseBinary   = true;
            request.Method      = WebRequestMethods.Ftp.ListDirectoryDetails;


            FtpWebResponse response       = null;
            Stream         responseStream = null;
            StreamReader   reader         = null;

            try
            {
                response = request.GetResponse() as FtpWebResponse;

                this.OnNewMessageArrived(new NewMessageEventArg
                {
                    NewMessage = response.StatusDescription
                });

                responseStream = response.GetResponseStream();
                //    reader = new StreamReader(responseStream);
                reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);

                List <FTPFileSystem> subDirs = new List <FTPFileSystem>();

                string subDir = reader.ReadLine();

                // Find out the FTP Directory Listing Style from the recordString.
                FTPDirectoryListingStyle style = FTPDirectoryListingStyle.MSDOS;
                if (!string.IsNullOrEmpty(subDir))
                {
                    style = FTPFileSystem.GetDirectoryListingStyle(subDir);
                }
                while (!string.IsNullOrEmpty(subDir))
                {
                    subDirs.Add(FTPFileSystem.ParseRecordString(url, subDir, style));

                    subDir = reader.ReadLine();
                }
                return(subDirs);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }

                // Close the StreamReader object and the underlying stream, and release
                // any system resources associated with the reader.
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
コード例 #2
0
ファイル: FTPClientManager.cs プロジェクト: tablesmit/OneCode
        /// <summary>
        /// 获得Url的子目录和文件. 对于所有的文件夹他将使用枚举.

        /// 在一个FTP 服务上,当运行FTP LIST 协议方法来获得一个文件的详细列表时,
        /// 这个服务将响应一些信息的记录。每一个记录代表一个文件。
        /// </summary>
        public IEnumerable <FTPFileSystem> GetSubDirectoriesAndFiles(Uri url)
        {
            FtpWebRequest request = WebRequest.Create(url) as FtpWebRequest;

            request.Credentials = this.Credentials;

            request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;


            FtpWebResponse response       = null;
            Stream         responseStream = null;
            StreamReader   reader         = null;

            try
            {
                response = request.GetResponse() as FtpWebResponse;

                this.OnNewMessageArrived(new NewMessageEventArg
                {
                    NewMessage = response.StatusDescription
                });

                responseStream = response.GetResponseStream();
                reader         = new StreamReader(responseStream);

                List <FTPFileSystem> subDirs = new List <FTPFileSystem>();

                string subDir = reader.ReadLine();

                //在记录的字符串中找到FTP目录列表类型.
                FTPDirectoryListingStyle style = FTPDirectoryListingStyle.MSDOS;
                if (!string.IsNullOrEmpty(subDir))
                {
                    style = FTPFileSystem.GetDirectoryListingStyle(subDir);
                }
                while (!string.IsNullOrEmpty(subDir))
                {
                    subDirs.Add(FTPFileSystem.ParseRecordString(url, subDir, style));

                    subDir = reader.ReadLine();
                }
                return(subDirs);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }

                // 关闭StreamReader对象和底层流,并且释放与reader有关的任何资源。

                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
コード例 #3
0
ファイル: FTPFileSystem.cs プロジェクト: zealoussnow/OneCode
        /// <summary>
        /// 从记录字符串得到一个FTPFileSystem
        /// </summary>
        public static FTPFileSystem ParseRecordString(Uri baseUrl, string recordString, FTPDirectoryListingStyle type)
        {
            FTPFileSystem fileSystem = null;

            if (type == FTPDirectoryListingStyle.UNIX)
            {
                fileSystem = ParseUNIXRecordString(recordString);
            }
            else
            {
                fileSystem = ParseMSDOSRecordString(recordString);
            }

            //如果是目录加“/”到路径
            fileSystem.Url = new Uri(baseUrl, fileSystem.Name + (fileSystem.IsDirectory ? "/" : string.Empty));

            return fileSystem;
        }
コード例 #4
0
        /// <summary>
        /// 从recordString中获得一个FTPFileSystem
        /// </summary>
        public static FTPFileSystem ParseRecordString(Uri baseUrl, string recordString, FTPDirectoryListingStyle type)
        {
            FTPFileSystem fileSystem = null;

            if (type == FTPDirectoryListingStyle.UNIX)
            {
                fileSystem = ParseUNIXRecordString(recordString);
            }
            else
            {
                fileSystem = ParseMSDOSRecordString(recordString);
            }

            // 如果它是一个目录我们将 "/"添加到Url中,

            fileSystem.Url = new Uri(baseUrl, fileSystem.Name + (fileSystem.IsDirectory ? "/" : string.Empty));

            return(fileSystem);
        }
コード例 #5
0
ファイル: FTPFileSystem.cs プロジェクト: zyangpointer/SDK
        /// <summary>
        /// Get an FTPFileSystem from the recordString.
        /// </summary>
        public static FTPFileSystem ParseRecordString(Uri baseUrl, string recordString, FTPDirectoryListingStyle type)
        {
            FTPFileSystem fileSystem = null;

            if (type == FTPDirectoryListingStyle.UNIX)
            {
                fileSystem = ParseUNIXRecordString(recordString);
            }
            else
            {
                fileSystem = ParseMSDOSRecordString(recordString);
            }

            string encodedName = EncodeUrl(fileSystem.Name);

            // Add "/" to the url if it is a directory
            fileSystem.Url = new Uri(baseUrl, encodedName + (fileSystem.IsDirectory ? "/" : string.Empty));

            return(fileSystem);
        }
コード例 #6
0
ファイル: FTPFileSystem.cs プロジェクト: NaraCheon/SDK
        /// <summary>
        /// Get an FTPFileSystem from the recordString. 
        /// </summary>
        public static FTPFileSystem ParseRecordString(Uri baseUrl, string recordString, FTPDirectoryListingStyle type)
        {
            FTPFileSystem fileSystem = null;

            if (type == FTPDirectoryListingStyle.UNIX)
            {
                fileSystem = ParseUNIXRecordString(recordString);
            }
            else
            {
                fileSystem = ParseMSDOSRecordString(recordString);
            }

            string encodedName = EncodeUrl(fileSystem.Name);

            // Add "/" to the url if it is a directory
            fileSystem.Url = new Uri(baseUrl, encodedName + (fileSystem.IsDirectory ? "/" : string.Empty));

            return fileSystem;
        }