Updated EFT creds, ZIPd archive

This commit is contained in:
Doug Macintosh
2026-03-31 10:06:25 -04:00
parent bfe37f6426
commit 2d86272a81
10 changed files with 433 additions and 147 deletions

105
SFTP.cs
View File

@@ -12,6 +12,25 @@ namespace bdf
{
public class sftp
{
public static ConnectionDetails sshPRODDetails = new ConnectionDetails
{
host = "mft.rogers.com",
ppkFile = "BDF.Embedded.mft_passphr.ppk", //Add "BDF.Embedded." to filename if embedded
passPhrase = "Rogers1!",
username = "PRD_3PTY_BDF",
//password = "f4H&&5igkEwP",
port = 50022
};
public static ConnectionDetails sshDEVDetails = new ConnectionDetails
{
host = "dev.mft.rogers.com",
ppkFile = "BDF.Embedded.private_passphr.ppk", //Add "BDF.Embedded." to filename if embedded
passPhrase = "Rogers1!",
username = "DEV_APP_BDF",
//password = "DEV_APP_BDF"
};
public class ConnectionDetails
{
public Int32 maxAttempts = 5;
@@ -94,7 +113,7 @@ namespace bdf
if (pkFile != null)
{
auth.Add(new Renci.SshNet.PrivateKeyAuthenticationMethod(cd.username, pkFile)); //preferred
Logger.Log(1, " -added PPK auth method.");
Logger.Log(2, " -added PPK auth method.");
}
}
@@ -110,7 +129,7 @@ namespace bdf
auth.Add(kb);
auth.Add(new Renci.SshNet.PasswordAuthenticationMethod(cd.username, cd.password));
Logger.Log(1, " -added user/pass auth method.");
Logger.Log(2, " -added user/pass auth method.");
}
return new Renci.SshNet.ConnectionInfo(cd.host, cd.port, cd.username, auth.ToArray())
@@ -210,7 +229,87 @@ namespace bdf
return false;
}
}
public static void Upload_DictStream(Dictionary<string,MemoryStream> Dict, string task, ConnectionDetails cd)
{
try
{
//using (var sftpClient = CreateClient(host, port, username, password))
var sftpInfo = BuildConnectionInfo(cd);
Renci.SshNet.SftpClient sftpClient = null;
try
{
sftpClient = TrySftpConnectWithHardTimeout(sftpInfo, cd.maxAttempts, cd.retrySecs);
}
catch (Renci.SshNet.Common.SshConnectionException e)
{
Logger.Log(1, " connection exception ({0}) : {1}", "", e.Message);
}
if (sftpClient == null)
{
Logger.Log(1, " null connection exception. Transfer failed.");
return;
}
string cpath = "";
foreach (var msFile in Dict)
{
string filename = "Outbox" + Path.DirectorySeparatorChar + task + Path.DirectorySeparatorChar + msFile.Key;
MemoryStream ms = msFile.Value;
cpath = EnsureSftpDirectoryExists(sftpClient, filename);
// file upload
try
{
ms.Position = 0;
sftpClient.UploadFile(
ms,
filename,
uploaded =>
{
Logger.Log(2, $"Uploaded {Math.Round((double)uploaded / ms.Length * 100)}% of the file.");
});
}
catch (Renci.SshNet.Common.SshException e)
{
Logger.Log(0, " SSH upload Exception {0}:{1}", e.Message, e.InnerException.Message);
}
Logger.Log(0, " -upload: {0} ({3}KB) to {1}:{2}", filename, cd.host, cd.port, (ms.Length / 1024) + 1);
}
//Console.WriteLine("starting dir pull {0}", cpath);
var files = sftpClient.ListDirectory(cpath).Where(f => f.IsRegularFile &&
(f.Name.EndsWith(".pdf", System.StringComparison.OrdinalIgnoreCase) || //pdf
f.Name.EndsWith(".zip", System.StringComparison.OrdinalIgnoreCase) || //pdf
f.Name.EndsWith(".xlsx", System.StringComparison.OrdinalIgnoreCase)));
Logger.Log(task, " EFT {0} Folder Contents:",task);
foreach (var s in files)
{
Logger.Log(task, " => {0} ({1}KB) {2}", s.FullName, (s.Attributes.Size/1024)+1, s.Attributes.LastWriteTime);
}
sftpClient.Disconnect();
Logger.Log("Disconnected");
try
{
sftpClient?.Dispose();
}
catch { }
return; // success
}
catch (Exception e)
{
Logger.Log(0, "SFTP exception {0}:{1}", e.Message, e.InnerException.Message);
}
}
public static void Upload_Stream(MemoryStream ms, string filename, ConnectionDetails cd)
{
try