我正在使用Tamir.SharpSsh.Sftp,想要从服务器获得所有的文件名,然后使用dynatree显示在页面上。
我的方法如下:
public List<DirectoryItem> ConnectSFTP(string address, string username, string password, Tamir.SharpSsh.Sftp ObjClient,string strfolder)
{
List<DirectoryItem> returnValue = new List<DirectoryItem>();
bool status = false;
try
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
//Tamir.SharpSsh.Sftp client = new Tamir.SharpSsh.Sftp(address + @"/ToNationwide/ivl00018/", username, password);
Tamir.SharpSsh.Sftp client = (ObjClient == null) ? new Tamir.SharpSsh.Sftp(address, username, password) : ObjClient;
client.Connect();
System.Collections.ArrayList arr = client.GetFileList(strfolder);
foreach (var item in arr)
{
if (item.ToString() != "." && item.ToString() != "..")
{
list.Add(item);
}
}
foreach (string line in list)
{
// Windows FTP Server Response Format
// DateCreated IsDirectory Name
// Parse <DIR>
bool isDirectory = client.GetFileList(strfolder+"/"+line).Count > 1;// Here i am confuse how to identify is directory or not ?
string name = line.ToString();
// Create directory info
DirectoryItem item = new DirectoryItem();
item.BaseUri = address;
item.IsDirectory = isDirectory;
item.Name = name;
item.Items = item.IsDirectory ? ConnectSFTP(item.AbsolutePath, username, password, client, "/"+line) : null;
returnValue.Add(item);
}
client.Close();
status = true;
}
catch (Exception ex)
{
}
return returnValue;
}
}所以请帮助任何这种类型的函数来检测文件或文件夹?
发布于 2015-07-08 04:26:05
你应该
try
{
SftpATTRS atributes = this.SftpChannel.stat(path);
return atributes.isDir();
}但对我来说,这是不起作用的,我得到了一个像目录这样的文件
https://stackoverflow.com/questions/28646432
复制相似问题