本文整理汇总了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);
}
}
}
}
示例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;
}
}
}
}