7

WinSCP 経由で C# を使用して FTPS サーバーに接続しようとしていますが、次のエラーが発生します。

SSH ホスト キーのフィンガープリント ... パターンと一致しません ...

大量の調査の結果、キーの長さと関係があると思います。「サーバーとプロトコル情報」の下のインターフェースを使用して接続したときにWinSCPから取得したキーは次のとおりです xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx が、例で見たものはこのように短いですxx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx

誰かが助けて、これを解決するための指針を教えてくれますか?

これが私のコードです

string winscpPath = "C:\\Program Files (x86)\\WinSCP\\WinSCP.exe";
string username = "User123";
string password = "abc1234";
string ftpSite = "192.168.5.110";
string localPath = "C:\\Users\\ttom\\Documents";
string remoteFTPDirectory = "/Usr/thisfolder";
string sshKey = "1b:68:10:80:77:c6:65:91:51:31:5t:65:1c:g6:13:20:39:g8:d8:6d";
Boolean winSCPLog = true;
string winSCPLogPath = "C:\\Users\\ttom\\Documents\\Visual Studio 2015\\Projects\\WebApplication1\\WebApplication1";

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = ftpSite,
    UserName = username,
    Password = password,
    SshHostKeyFingerprint = sshKey
};

using (Session session = new Session())
{
    // WinSCP .NET assembly must be in GAC to be used with SSIS,
    // set path to WinSCP.exe explicitly, if using non-default path.
    session.ExecutablePath = winscpPath;
    session.DisableVersionCheck = true;

    if (winSCPLog)
    {
        session.SessionLogPath = @winSCPLogPath + @"ftplog.txt";
        session.DebugLogPath = @winSCPLogPath + @"debuglog.txt";
    }

    // Connect
    session.Timeout = new TimeSpan(0, 2, 0); // two minutes
    session.Open(sessionOptions);

    TransferOptions transferOptions = new TransferOptions();
    transferOptions.TransferMode = TransferMode.Binary;

    session.GetFiles(remoteFTPDirectory + "/" +
        "test.txt", localPath, false, transferOptions);
}

ここに画像の説明を入力

4

4 に答える 4

4

コードでは SFTP (SSH 経由) を使用して接続していますが、GUI では FTPS (TLS/SSL 経由の FTP) を使用しています。

これらは 2 つの完全に異なるプロトコルです

Protocol = Protocol.Ftpを使用して TLS/SSL を使用および有効にしますFtpSecure = FtpSecure.Explicit

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Ftp,
    FtpSecure = FtpSecure.Explicit,
    HostName = ftpSite,
    UserName = username,
    Password = password,
};

SshHostKeyFingerprintFTPS に相当するものはTlsHostCertificateFingerprint. ただし、TLS/SSL 証明書が信頼できる機関 (自己署名証明書など) によって署名されていない場合にのみ使用する必要があります。


最も簡単なのは、WinSCP GUI にコードを生成させることです。

于 2016-01-28T06:58:34.937 に答える
2

私も同じエラーがありました。私の場合、SSH 指紋キーをコピーした PC が、開発用 PC よりも新しいバージョンの WinSCP を実行していることを発見しました。

開発用 PC で WinSCP.exe ファイルと WinSCPnet.DLL ファイルを更新すると、問題が解決しました。

于 2018-03-16T11:41:45.690 に答える
1

私は同様のタスクに取り組んでいます。指紋文字列の前に「ssh-rsa」を付けてみましたか?

すべてが私の側で機能しているように見えるので、ここで2つのことが起こっている可能性があると私は信じています.

  1. 認証文字列の一部が欠落している可能性があります。

    string SshHostKeyFingerpring = "ssh-rsa XXXX 1b:68:10:80:77:c6:65:91:51:31:5t:65:1c:g6:13:20:39:g8:d8:6d";
    

    および/または

  2. 2 つのプロトコルを使用しています。SFTP と FTPS

于 2016-04-18T18:00:53.740 に答える