我试图通过C#中的FtpWebRequest类来实现ftp/sftp,但直到现在还没有成功.
我不想使用任何第三方免费或付费的dll.
凭证就像
我能够使用IP地址实现ftp,但无法使用凭据获取上述主机名的sftp.
对于sftp,我已将FtpWebRequest类的EnableSsl属性设置为true,但是错误无法连接到远程服务器.
我能够使用相同的凭据和主机名与Filezilla连接,但不能通过代码连接.
我观察了filezilla,它将主机名从sftp.xyz.com更改为文本框中的sftp://sftp.xyz.com,在命令行中将用户标识更改为abc@sftp.xyz.com
我在代码中做了同样的事情,但sftp没有成功.
请急需帮助.提前致谢.
以下是我目前的代码:
private static void ProcessSFTPFile()
{
try
{
string[] fileList = null;
StringBuilder result = new StringBuilder();
string uri = "ftp://sftp.xyz.com";
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(new Uri(uri));
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
ftpRequest.EnableSsl = true;
ftpRequest.Credentials = new NetworkCredential("abc@sftp.xyz.com", "123");
ftpRequest.UsePassive = true;
ftpRequest.Timeout = System.Threading.Timeout.Infinite;
//ftpRequest.AuthenticationLevel = Security.AuthenticationLevel.MutualAuthRequested;
//ftpRequest.Proxy = null;
ftpRequest.KeepAlive = true;
ftpRequest.UseBinary = true;
//Hook a callback to verify the remote certificate …Run Code Online (Sandbox Code Playgroud)