|
5 | 5 | using System.Text;
|
6 | 6 | using System.Threading;
|
7 | 7 | using System.Windows.Media.Imaging;
|
| 8 | +using _1RM.Utils; |
8 | 9 | using Renci.SshNet;
|
9 | 10 | using Renci.SshNet.Sftp;
|
10 | 11 | using Shawn.Utils;
|
@@ -300,24 +301,21 @@ private void InitClient()
|
300 | 301 | if (_sftp?.IsConnected != true)
|
301 | 302 | {
|
302 | 303 | _sftp?.Dispose();
|
303 |
| - if (string.IsNullOrEmpty(Password)) |
| 304 | + if (string.IsNullOrEmpty(Password) |
| 305 | + && string.IsNullOrEmpty(SshKeyPath) == false |
| 306 | + && File.Exists(SshKeyPath)) |
304 | 307 | {
|
305 |
| - var connectionInfo = new ConnectionInfo(Hostname, Port, Username, |
306 |
| - new AuthenticationMethod[] |
307 |
| - { |
308 |
| - new PrivateKeyAuthenticationMethod(Username, new PrivateKeyFile(SshKeyPath)), |
309 |
| - }); |
310 |
| - _sftp = new SftpClient(connectionInfo); |
311 |
| - } |
312 |
| - else |
313 |
| - { |
314 |
| - var connectionInfo = new ConnectionInfo(Hostname, Port, Username, |
315 |
| - new AuthenticationMethod[] |
316 |
| - { |
317 |
| - new PasswordAuthenticationMethod(Username, Password), |
318 |
| - }); |
319 |
| - _sftp = new SftpClient(connectionInfo); |
| 308 | + try |
| 309 | + { |
| 310 | + var connectionInfo = new ConnectionInfo(Hostname, Port, Username, new PrivateKeyAuthenticationMethod(Username, new PrivateKeyFile(SshKeyPath))); |
| 311 | + _sftp = new SftpClient(connectionInfo); |
| 312 | + } |
| 313 | + catch (Exception e) |
| 314 | + { |
| 315 | + MsAppCenterHelper.Error(e); |
| 316 | + } |
320 | 317 | }
|
| 318 | + _sftp ??= new SftpClient(new ConnectionInfo(Hostname, Port, Username, new PasswordAuthenticationMethod(Username, Password))); |
321 | 319 | //_sftp.KeepAliveInterval = new TimeSpan(0, 0, 10);
|
322 | 320 | _sftp.Connect();
|
323 | 321 | }
|
|
0 commit comments