我正在使用devart SecureBridge通過SFTP創建連接,並且在SSHClient上設置身份驗證類型時遇到問題。設置身份驗證類型SFTP連接delphi
當我嘗試沒有它給我一個例外:'主機密鑰算法的協商失敗'。我想這是試圖使用私人/公共密鑰,但我希望它使用密碼認證。
這是我的代碼,我希望有人能指引我在正確的方向。
oSSHClient := TScSSHClient.Create(nil);
oSFTPClient := nil;
oFileStorage := nil;
oFileStorage := TScFileStorage.Create(nil);
oSSHClient.KeyStorage := oFileStorage;
iColon := pos(':', edHost.text);
oSSHClient.HostName := edHost.Text;
if iColon > 0 then
begin
oSSHClient.Port := StrToIntDef(copy(edHost.Text, iColon+1, length(edHost.Text)), 22);
end;
oSSHClient.User := edUser.Text;
oSSHClient.Password := edPassword.Text;
oSSHClient.Authentication := oSSHClient.Authentication.atPassword; // How am i supposed to set this
oSSHClient.Connect;
編輯:工作的代碼給別人看:
oSSHClient := TScSSHClient.Create(nil);
oFileStorage := nil;
try
oFileStorage := TScFileStorage.Create(nil);
oSSHClient.KeyStorage := oFileStorage;
iColon := pos(':', edHost.text);
oSSHClient.HostName := edHost.Text;
if iColon > 0 then
begin
oSSHClient.Port := StrToIntDef(copy(edHost.Text, iColon+1, length(edHost.Text)), 22);
end;
oSSHClient.User := edUser.Text;
oSSHClient.Password := edPassword.Text;
oSSHClient.HostKeyAlgorithms.AsString:='ssh-rsa,ssh-dss';
oSSHClient.OnServerKeyValidate := ScSSHClientServerKeyValidate;
oSSHClient.Authentication := atPassword;
try
try
oSSHClient.Connect;
TestErrorTekst := GetLang('CaptConnectToServerOK');
except
TestErrorTekst := GetLang('CaptConnectToServerFailed');
end;
finally
oSSHClient.Disconnect;
end;
finally
edTest.Text := TestErrorTekst;
oSSHClient.Free;
oFileStorage.Free;
end;
由於沒有其他人跳進來,我會給出一個明確的非專家意見。我的理解是身份驗證與安全套接字層(SSL)有關,而與密碼無關。這是一種加密技術,可確保數據在客戶端和服務器之間安全傳遞。密碼是一個額外的安全層,以確保數據安全,使用該數據的人有權訪問FTP站點。 – Dsm