請問一下為什麼這樣寫執行到openread那一行後都會顯示權限不足呢?
我上網翻了許久都翻不到,請求大神幫助,感謝您。
using System;
using Renci.SshNet;
using Renci.SshNet.Sftp;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Xml;
//連接SFTP之功能
namespace ConsoleApp1
{
class Program
{
private static string _host = "";
private static string _username = "";
private static string _password = "";
static void Main(string[] args)
{
var sftp = new SftpClient(_host, _username, _password);
try
{
sftp.Connect();
if (sftp != null)
{
string a = collectDoc(sftp);
if (a != "f")
{
var doc = new XmlDocument();
doc.Load(sftp.OpenRead(a));
PackDocument pD = new PackDocument(a,doc);
}
else
{
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
if (sftp != null || sftp.IsConnected)
{
sftp.Disconnect();
}
}
}
//取得所有檔案
private static string collectDoc(SftpClient sftp)
{
string errorMessage = "";
List<string> fileList = new List<string>();
//using(sftp)
//{
Action<SftpFile> ShowDirOrFile = (item) =>
{
if (item.IsDirectory)
{
Console.WriteLine($"[{item.Name}]");
}
else
{
Console.WriteLine($"[{item.Name:-32}{item.Length,8:N0}]");
}
};
Action<string> Dir = (path) =>
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"Directory of {path}: \n");
var list = sftp.ListDirectory(path).Where(o => !".,..".Split(',').Contains(o.Name)).ToList();
if (list.Any())
{
list.ForEach(ShowDirOrFile);
}
else
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("NO files.");
}
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
};
Dir("/");
var listDirectory = sftp.ListDirectory("/");
try
{
foreach (var i in listDirectory)
{
string xmlName = i.Name;
return xmlName;
}
}
catch (Exception e)
{
Console.WriteLine(e);
return "f";
}
return "f";
//}
}
}
}