@@ -31,18 +31,20 @@ class SSHHandler : BaseRemoteHandler
3131 private string SudoImpersonatedUser { get ; set ; }
3232 private ApplicationSettings . FileTransferProtocolEnum FileTransferProtocol { get ; set ; }
3333 private bool IsStoreServerLinux { get ; set ; }
34+ private bool UseShellCommands { get ; set ; }
3435 private string UserId { get ; set ; }
3536 private string Password { get ; set ; }
3637 private SshClient sshClient ;
3738
38- internal SSHHandler ( string server , string serverLogin , string serverPassword , bool isStoreServerLinux , ApplicationSettings . FileTransferProtocolEnum fileTransferProtocol , int sshPort , string sudoImpersonatedUser )
39+ internal SSHHandler ( string server , string serverLogin , string serverPassword , bool isStoreServerLinux , ApplicationSettings . FileTransferProtocolEnum fileTransferProtocol , int sshPort , string sudoImpersonatedUser , bool useShellCommands )
3940 {
4041 _logger . MethodEntry ( LogLevel . Debug ) ;
4142
4243 Server = server ;
4344 SudoImpersonatedUser = sudoImpersonatedUser ;
4445 FileTransferProtocol = fileTransferProtocol ;
4546 IsStoreServerLinux = isStoreServerLinux ;
47+ UseShellCommands = useShellCommands ;
4648 UserId = serverLogin ;
4749 Password = serverPassword ;
4850
@@ -80,7 +82,8 @@ internal SSHHandler(string server, string serverLogin, string serverPassword, bo
8082 sshClient . Connect ( ) ;
8183
8284 //method call below necessary to check edge condition where password for user id has expired. SCP (and possibly SFTP) download hangs in that scenario
83- CheckConnection ( ) ;
85+ if ( useShellCommands )
86+ CheckConnection ( ) ;
8487 }
8588 catch ( Exception ex )
8689 {
@@ -368,13 +371,20 @@ public override void CreateEmptyStoreFile(string path, string linuxFilePermissio
368371 if ( IsStoreServerLinux )
369372 {
370373 string pathOnly = string . Empty ;
371- SplitStorePathFile ( path , out pathOnly , out _ ) ;
374+ string fileName = string . Empty ;
375+ SplitStorePathFile ( path , out pathOnly , out fileName ) ;
372376
373- linuxFilePermissions = string . IsNullOrEmpty ( linuxFilePermissions ) ? GetFolderPermissions ( pathOnly ) : linuxFilePermissions ;
374- linuxFileOwner = string . IsNullOrEmpty ( linuxFileOwner ) ? GetFolderOwner ( pathOnly ) : linuxFileOwner ;
377+ if ( UseShellCommands )
378+ {
379+ linuxFilePermissions = string . IsNullOrEmpty ( linuxFilePermissions ) ? GetFolderPermissions ( pathOnly ) : linuxFilePermissions ;
380+ linuxFileOwner = string . IsNullOrEmpty ( linuxFileOwner ) ? GetFolderOwner ( pathOnly ) : linuxFileOwner ;
381+
382+ AreLinuxPermissionsValid ( linuxFilePermissions ) ;
375383
376- AreLinuxPermissionsValid ( linuxFilePermissions ) ;
377- RunCommand ( $ "install -m { linuxFilePermissions } -o { linuxFileOwner } { linuxFileGroup } /dev/null { path } ", null , ApplicationSettings . UseSudo , null ) ;
384+ RunCommand ( $ "install -m { linuxFilePermissions } -o { linuxFileOwner } { linuxFileGroup } /dev/null { path } ", null , ApplicationSettings . UseSudo , null ) ;
385+ }
386+ else
387+ UploadCertificateFile ( pathOnly , fileName , Array . Empty < byte > ( ) ) ;
378388 }
379389 else
380390 RunCommand ( $@ "Out-File -FilePath ""{ path } """, null, false, null);
@@ -386,28 +396,38 @@ public override bool DoesFileExist(string path)
386396 {
387397 _logger . MethodEntry ( LogLevel . Debug ) ;
388398 _logger. LogDebug ( $ "DoesFileExist: { path } ") ;
389-
390- string rtn = RunCommand( $ "ls { path } >> /dev/null 2>&1 && echo True || echo False", null , ApplicationSettings . UseSudo , null ) ;
391- return Convert. ToBoolean ( rtn ) ;
392-
393- //using (SftpClient client = new SftpClient(Connection))
394- //{
395- // try
396- // {
397- // client.Connect();
398- // string existsPath = FormatFTPPath(path, !IsStoreServerLinux);
399- // bool exists = client.Exists(existsPath);
400- // _logger.LogDebug(existsPath);
401-
402- // _logger.MethodExit(LogLevel.Debug);
403-
404- // return exists;
405- // }
406- // finally
407- // {
408- // client.Disconnect();
409- // }
410- //}
399+
400+ bool exists = false;
401+
402+ if ( UseShellCommands )
403+ {
404+ exists = Convert. ToBoolean ( RunCommand ( $ "ls { path } >> /dev/null 2>&1 && echo True || echo False", null , ApplicationSettings . UseSudo , null ) ) ;
405+ }
406+ else
407+ {
408+ using ( SftpClient client = new SftpClient ( Connection ) )
409+ {
410+ try
411+ {
412+ client. Connect ( ) ;
413+ string existsPath = FormatFTPPath( path, ! IsStoreServerLinux ) ;
414+ exists = client. Exists ( existsPath ) ;
415+ _logger. LogDebug ( existsPath ) ;
416+ }
417+ catch ( Exception ex )
418+ {
419+ _logger. LogError ( RemoteFileException . FlattenExceptionMessages ( ex , "Error checking existence of file {path} using SFTP" ) ) ;
420+ throw ;
421+ }
422+ finally
423+ {
424+ _logger. MethodExit ( LogLevel . Debug ) ;
425+ client. Disconnect ( ) ;
426+ }
427+ }
428+ }
429+
430+ return exists;
411431 }
412432
413433 public override void RemoveCertificateFile ( string path , string fileName )
0 commit comments