/// <summary>
/// Lists the files.
/// </summary>
/// <param name="remotePath">The remote path.</param>
/// <param name="failRemoteNotExists">if set to <c>true</c> [fail remote not exists].</param>
/// <returns></returns>
/// <exception cref="System.Exception"></exception>
public List<IRemoteFileInfo> ListFiles(string remotePath)
{
List<IRemoteFileInfo> fileList = new List<IRemoteFileInfo>();
try
{
this.Log(String.Format("Connecting to Host: [{0}].", this.hostName), LogLevel.Minimal);
using (SftpClient sftp = new SftpClient(this.hostName, this.portNumber, this.userName, this.passWord))
{
sftp.Connect();
this.Log(String.Format("Connected to Host: [{0}].", this.hostName), LogLevel.Verbose);
if (!sftp.Exists(remotePath))
{
this.Log(String.Format("Remote Path Does Not Exist: [{0}].", this.hostName), LogLevel.Verbose);
if (this.stopOnFailure)
throw new Exception(String.Format("Invalid Path: [{0}]", remotePath));
}
else
{
this.Log(String.Format("Listing Files: [{0}].", remotePath), LogLevel.Minimal);
this.Log(String.Format("Getting Attributes: [{0}].", remotePath), LogLevel.Verbose);
SftpFile sftpFileInfo = sftp.Get(remotePath);
if (sftpFileInfo.IsDirectory)
{
this.Log(String.Format("Path is a Directory: [{0}].", remotePath), LogLevel.Verbose);
IEnumerable<SftpFile> dirList = sftp.ListDirectory(remotePath);
foreach (SftpFile sftpFile in dirList)
fileList.Add(this.CreateFileInfo(sftpFile));
}
else
{
this.Log(String.Format("Path is a File: [{0}].", remotePath), LogLevel.Verbose);
fileList.Add(this.CreateFileInfo(sftpFileInfo));
}
}
}
this.Log(String.Format("Disconnected from Host: [{0}].", this.hostName), LogLevel.Minimal);
}
catch (Exception ex)
{
this.Log(String.Format("Disconnected from Host: [{0}].", this.hostName), LogLevel.Minimal);
this.ThrowException("Unable to List: ", ex);
}
return fileList;
}