当前位置: 首页>>代码示例>>C#>>正文


C# FtpClient.DereferenceLink方法代码示例

本文整理汇总了C#中FtpClient.DereferenceLink方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.DereferenceLink方法的具体用法?C# FtpClient.DereferenceLink怎么用?C# FtpClient.DereferenceLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FtpClient的用法示例。


在下文中一共展示了FtpClient.DereferenceLink方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DereferenceLinkExample

        /// <summary>
        /// Example illustrating how to dereference a symbolic link
        /// in a file listing. You can also pass the FtpListOption.DerefLinks
        /// flag to GetListing() to have automatically done in which
        /// case the FtpListItem.LinkObject property will contain the
        /// FtpListItem representing the object the link points at. The
        /// LinkObject property will be null if there was a problem resolving
        /// the target.
        /// </summary>
        public static void DereferenceLinkExample() {
            using (FtpClient client = new FtpClient()) {
                client.Credentials = new NetworkCredential("user", "pass");
                client.Host = "somehost";

                // This propety controls the depth of recursion that
                // can be done before giving up on resolving the link.
                // You can set the value to -1 for infinite depth 
                // however you are strongly discourage from doing so.
                // The default value is 20, the following line is
                // only to illustrate the existance of the property.
                // It's also possible to override this value as one
                // of the overloaded arguments to the DereferenceLink() method.
                client.MaximumDereferenceCount = 20;

                // Notice the FtpListOption.ForceList flag being passed. This is because
                // symbolic links are only supported in UNIX style listings. My personal
                // experience has been that in practice MLSD listings don't specify an object
                // as a link, but rather list the link as a regular file or directory
                // accordingly. This may not always be the case however that's what I've
                // observed over the life of this project so if you run across the contrary
                // please report it. The specification for MLSD does include links so it's
                // possible some FTP server implementations do include links in the MLSD listing.
                foreach (FtpListItem item in client.GetListing(null, FtpListOption.ForceList | FtpListOption.Modify)) {
                    Console.WriteLine(item);

                    // If you call DerefenceLink() on a FtpListItem.Type other
                    // than Link a FtpException will be thrown. If you call the
                    // method and the LinkTarget is null a FtpException will also
                    // be thrown.
                    if (item.Type == FtpFileSystemObjectType.Link && item.LinkTarget != null) {
                        item.LinkObject = client.DereferenceLink(item);

                        // The return value of DerefenceLink() will be null
                        // if there was a problem.
                        if (item.LinkObject != null) {
                            Console.WriteLine(item.LinkObject);
                        }
                    }
                }

                // This example is similar except it uses the FtpListOption.DerefLinks
                // flag to have symbolic links automatically resolved. You must manually
                // specify this flag because of the added overhead with regards to resolving
                // the target of a link.
                foreach (FtpListItem item in client.GetListing(null,
                    FtpListOption.ForceList | FtpListOption.Modify | FtpListOption.DerefLinks)) {

                    Console.WriteLine(item);

                    if (item.Type == FtpFileSystemObjectType.Link && item.LinkObject != null) {
                        Console.WriteLine(item.LinkObject);
                    }
                }
            }
        }
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:65,代码来源:DereferenceLink.cs

示例2: GetListing

        public static void GetListing() {
            using (FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                
                foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory(),
                    FtpListOption.Modify | FtpListOption.Size)) {

                    switch (item.Type) {
                        case FtpFileSystemObjectType.Directory:
                            break;
                        case FtpFileSystemObjectType.File:
                            break;
                        case FtpFileSystemObjectType.Link:
                            // derefernece symbolic links
                            if (item.LinkTarget != null) {
                                // see the DereferenceLink() example
                                // for more details about resolving links.
                                item.LinkObject = conn.DereferenceLink(item);

                                if (item.LinkObject != null) {
                                    // switch (item.LinkObject.Type)...
                                }
                            }
                            break;
                    }
                }

                // same example except automatically dereference symbolic links.
                // see the DereferenceLink() example for more details about resolving links.
                foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory(),
                    FtpListOption.Modify | FtpListOption.Size | FtpListOption.DerefLinks)) {

                    switch (item.Type) {
                        case FtpFileSystemObjectType.Directory:
                            break;
                        case FtpFileSystemObjectType.File:
                            break;
                        case FtpFileSystemObjectType.Link:
                            if (item.LinkObject != null) {
                                // switch (item.LinkObject.Type)...
                            }
                            break;
                    }
                }
            }
        }
开发者ID:Kylia669,项目名称:DiplomWork,代码行数:47,代码来源:GetListing.cs


注:本文中的FtpClient.DereferenceLink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。