Reputation: 44
I am using Tamir.SharpSsh.Sftp and want to get all file name from the server and then want to show on page using dynatree.
my method is here :
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;
}
}
so please help any such type of function to detect file or folder ?
Upvotes: 1
Views: 1919
Reputation: 41
You should
try
{
SftpATTRS atributes = this.SftpChannel.stat(path);
return atributes.isDir();
}
But for me, it's not working I am getting a file like a Directory
Upvotes: 1