本文整理汇总了C#中SftpClient.ListDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.ListDirectory方法的具体用法?C# SftpClient.ListDirectory怎么用?C# SftpClient.ListDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SftpClient
的用法示例。
在下文中一共展示了SftpClient.ListDirectory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Sftp_ListDirectory_Without_Connecting
public void Test_Sftp_ListDirectory_Without_Connecting()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
var files = sftp.ListDirectory(".");
foreach (var file in files)
{
Debug.WriteLine(file.FullName);
}
}
}
示例2: Test_Sftp_ListDirectory_Not_Exists
public void Test_Sftp_ListDirectory_Not_Exists()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
var files = sftp.ListDirectory("/asdfgh");
foreach (var file in files)
{
Debug.WriteLine(file.FullName);
}
sftp.Disconnect();
}
}
示例3: Test_Sftp_ListDirectory_Current
public void Test_Sftp_ListDirectory_Current()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
var files = sftp.ListDirectory(".");
Assert.IsTrue(files.Count() > 0);
foreach (var file in files)
{
Debug.WriteLine(file.FullName);
}
sftp.Disconnect();
}
}
示例4: Test_Sftp_Change_Directory
public void Test_Sftp_Change_Directory()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester");
sftp.CreateDirectory("test1");
sftp.ChangeDirectory("test1");
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1");
sftp.CreateDirectory("test1_1");
sftp.CreateDirectory("test1_2");
sftp.CreateDirectory("test1_3");
var files = sftp.ListDirectory(".");
Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}", sftp.WorkingDirectory)));
sftp.ChangeDirectory("test1_1");
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1");
sftp.ChangeDirectory("../test1_2");
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_2");
sftp.ChangeDirectory("..");
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1");
sftp.ChangeDirectory("..");
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester");
files = sftp.ListDirectory("test1/test1_1");
Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory)));
sftp.ChangeDirectory("test1/test1_1");
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1");
sftp.ChangeDirectory("/home/tester/test1/test1_1");
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1");
sftp.ChangeDirectory("/home/tester/test1/test1_1/../test1_2");
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_2");
sftp.ChangeDirectory("../../");
sftp.DeleteDirectory("test1/test1_1");
sftp.DeleteDirectory("test1/test1_2");
sftp.DeleteDirectory("test1/test1_3");
sftp.DeleteDirectory("test1");
sftp.Disconnect();
}
}
示例5: Test_Sftp_ListDirectory_Permission_Denied
public void Test_Sftp_ListDirectory_Permission_Denied()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
var files = sftp.ListDirectory("/etc/audit");
foreach (var file in files)
{
Debug.WriteLine(file.FullName);
}
sftp.Disconnect();
}
}
示例6: Test_Sftp_ListDirectory_HugeDirectory
public void Test_Sftp_ListDirectory_HugeDirectory()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
// Create 10000 directory items
for (int i = 0; i < 10000; i++)
{
sftp.CreateDirectory(string.Format("test_{0}", i));
Debug.WriteLine("Created " + i);
}
var files = sftp.ListDirectory(".");
// Ensure that directory has at least 10000 items
Assert.IsTrue(files.Count() > 10000);
sftp.Disconnect();
}
}
示例7: GetFilesRecur
private IEnumerable<SftpFile> GetFilesRecur(SftpClient ssh, SftpFile sftpDir)
{
if (!sftpDir.IsDirectory)
{
return new[] {sftpDir};
}
var fl = new List<SftpFile>();
foreach (var sftpFile in ssh.ListDirectory(sftpDir.FullName))
{
if (sftpFile.IsRegularFile)
{
fl.Add(sftpFile);
}
else if (sftpFile.IsDirectory && sftpFile.Name != "." && sftpFile.Name != "..")
{
fl.AddRange(GetFilesRecur(ssh, sftpFile));
}
}
return fl;
}
示例8: button1_Click
private void button1_Click(object sender, EventArgs e)
{
try
{
/*if (AllFieldsSet() == false)
{
Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg,
Language.strPleaseFillAllFields);
return;
}*/
lvSSHFileBrowser.Items.Clear();
var ssh = new SftpClient(txtHost.Text, int.Parse(this.txtPort.Text), txtUser.Text, txtPassword.Text);
ssh.Connect();
var res = ssh.ListDirectory(txtRemoteFolderPath.Text).ToList().OrderBy(file => !file.IsDirectory).ThenBy(file => file.Name);
var l = new List<EXImageListViewItem>();
foreach (var item in res)
{
if (item.Name==".")
{
continue;
}
EXImageListViewItem imglstvitem = new EXImageListViewItem();
imglstvitem.MyImage = item.IsDirectory ? global::My.Resources.Resources.Folder : global::My.Resources.Resources.File;
imglstvitem.MyValue = item.FullName;
imglstvitem.Tag = item;
imglstvitem.SubItems.Add(item.Name);
imglstvitem.SubItems.Add(item.IsDirectory ? "" : Tools.Misc.LengthToHumanReadable(item.Length));
l.Add(imglstvitem);
}
ssh.Disconnect();
lvSSHFileBrowser.Items.AddRange(l.ToArray());
lvSSHFileBrowser.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例9: ListDirectoryTest
public void ListDirectoryTest()
{
ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value
string path = string.Empty; // TODO: Initialize to an appropriate value
Action<int> listCallback = null; // TODO: Initialize to an appropriate value
IEnumerable<SftpFile> expected = null; // TODO: Initialize to an appropriate value
IEnumerable<SftpFile> actual;
actual = target.ListDirectory(path, listCallback);
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}