Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
leefine02 authored and leefine02 committed Jun 7, 2024
1 parent 77e2a24 commit 6447e79
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Binary file removed RemoteFile/External References/Renci.SshNet.dll
Binary file not shown.
Binary file not shown.
7 changes: 2 additions & 5 deletions RemoteFile/RemoteFile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="Keyfactor.Logging" Version="1.1.1" />
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="0.7.0" />
<PackageReference Include="Keyfactor.PKI" Version="5.0.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.12" />
</ItemGroup>

<ItemGroup>
<Folder Include="External References\" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 20 additions & 4 deletions RemoteFile/RemoteHandlers/SSHHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public override void Initialize()
{
sshClient = new SshClient(Connection);
sshClient.Connect();

//method call below necessary to check edge condition where password for user id has expired. SCP (and possibly SFTP) download hangs in that scenario
CheckConnection();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -146,7 +149,7 @@ public override string RunCommand(string commandText, object[] arguments, bool w
catch (Exception ex)
{
_logger.LogError($"Exception during RunCommand...{RemoteFileException.FlattenExceptionMessages(ex, ex.Message)}");
throw ex;
throw;
}
}

Expand Down Expand Up @@ -328,18 +331,18 @@ public override void CreateEmptyStoreFile(string path, string linuxFilePermissio
{
_logger.MethodEntry(LogLevel.Debug);
string[] linuxGroupOwner = linuxFileOwner.Split(":");
string linuxFileGroup = linuxFileOwner;
string linuxFileGroup = String.Empty;

if (linuxGroupOwner.Length == 2)
{
linuxFileOwner = linuxGroupOwner[0];
linuxFileGroup = linuxGroupOwner[1];
linuxFileGroup = $"-g {linuxGroupOwner[1]}";
}

if (IsStoreServerLinux)
{
AreLinuxPermissionsValid(linuxFilePermissions);
RunCommand($"install -m {linuxFilePermissions} -o {linuxFileOwner} -g {linuxFileGroup} /dev/null {path}", null, ApplicationSettings.UseSudo, null);
RunCommand($"install -m {linuxFilePermissions} -o {linuxFileOwner} {linuxFileGroup} /dev/null {path}", null, ApplicationSettings.UseSudo, null);
}
else
RunCommand($@"Out-File -FilePath ""{path}""", null, false, null);
Expand Down Expand Up @@ -431,5 +434,18 @@ private string FormatFTPPath(string path, bool addLeadingSlashForWindows)

return rtnPath;
}

private void CheckConnection()
{
try
{
RunCommand("echo", null, ApplicationSettings.UseSudo, null);
}
catch (Exception ex)
{
_logger.LogError(RemoteFileException.FlattenExceptionMessages(ex, "Error validating server connection."));
throw;
}
}
}
}

0 comments on commit 6447e79

Please sign in to comment.