小编pan*_*321的帖子

如果可能,在C#中使用FtpWebRequest实现没有第三方dll的FTP/SFTP

我试图通过C#中的FtpWebRequest类来实现ftp/sftp,但直到现在还没有成功.

我不想使用任何第三方免费或付费的dll.

凭证就像

  1. hostname = sftp.xyz.com
  2. userid = abc
  3. 密码= 123

我能够使用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)

.net c# winforms

13
推荐指数
3
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1

winforms ×1