@@ -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,18 @@ 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
373377 linuxFilePermissions = string . IsNullOrEmpty ( linuxFilePermissions ) ? GetFolderPermissions ( pathOnly ) : linuxFilePermissions ;
374378 linuxFileOwner = string . IsNullOrEmpty ( linuxFileOwner ) ? GetFolderOwner ( pathOnly ) : linuxFileOwner ;
375379
376380 AreLinuxPermissionsValid ( linuxFilePermissions ) ;
377- RunCommand ( $ "install -m { linuxFilePermissions } -o { linuxFileOwner } { linuxFileGroup } /dev/null { path } ", null , ApplicationSettings . UseSudo , null ) ;
381+
382+ if ( UseShellCommands )
383+ RunCommand ( $ "install -m { linuxFilePermissions } -o { linuxFileOwner } { linuxFileGroup } /dev/null { path } ", null , ApplicationSettings . UseSudo , null ) ;
384+ else
385+ UploadCertificateFile ( pathOnly , fileName , Array . Empty < byte > ( ) ) ;
378386 }
379387 else
380388 RunCommand ( $@ "Out-File -FilePath ""{ path } """, null, false, null);
@@ -386,28 +394,38 @@ public override bool DoesFileExist(string path)
386394 {
387395 _logger . MethodEntry ( LogLevel . Debug ) ;
388396 _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- //}
397+
398+ bool exists = false;
399+
400+ if ( UseShellCommands )
401+ {
402+ exists = Convert. ToBoolean ( RunCommand ( $ "ls { path } >> /dev/null 2>&1 && echo True || echo False", null , ApplicationSettings . UseSudo , null ) ) ;
403+ }
404+ else
405+ {
406+ using ( SftpClient client = new SftpClient ( Connection ) )
407+ {
408+ try
409+ {
410+ client. Connect ( ) ;
411+ string existsPath = FormatFTPPath( path, ! IsStoreServerLinux ) ;
412+ exists = client. Exists ( existsPath ) ;
413+ _logger. LogDebug ( existsPath ) ;
414+ }
415+ catch ( Exception ex )
416+ {
417+ _logger. LogError ( RemoteFileException . FlattenExceptionMessages ( ex , "Error checking existence of file {path} using SFTP" ) ) ;
418+ throw ;
419+ }
420+ finally
421+ {
422+ _logger. MethodExit ( LogLevel . Debug ) ;
423+ client. Disconnect ( ) ;
424+ }
425+ }
426+ }
427+
428+ return exists;
411429 }
412430
413431 public override void RemoveCertificateFile ( string path , string fileName )
0 commit comments