When trying to download a large file from my SCP server it always stops at 476 MB. I tried
sessionOptions.AddRawSettings("SendBuf", "0");
sessionOptions.AddRawSettings("SshSimple ", "0");
But still can't do it. Here is my code:
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Scp,
HostName = "192.168.10.1",
UserName = "******",
Password = "******",
SshHostKeyPolicy = SshHostKeyPolicy.GiveUpSecurityAndAcceptAny
};
// Connect to the remote server and download files
using (Session session = new Session())
{
session.ReconnectTime = TimeSpan.FromSeconds(2);
sessionOptions.AddRawSettings("SendBuf", "0");
sessionOptions.AddRawSettings("SshSimple ", "0");
session.Open(sessionOptions);
string remotePath = "/mnt/hdd_1/mstore/QLIVE.vfdp/storage/1001_NileSatDocuments_220101010000_250101120000/";
var opts = EnumerationOptions.EnumerateDirectories | EnumerationOptions.AllDirectories;
IEnumerable<RemoteFileInfo> fileInfos = session.EnumerateRemoteFiles(remotePath, null, opts);
foreach (RemoteFileInfo fileInfo in fileInfos)
{
if (fileInfo.IsDirectory)
{
continue; // skip directories
}
// Determine local and remote file paths
string remoteFilePath = RemotePath.EscapeFileMask(fileInfo.FullName);
string localFilePath = RemotePath.TranslateRemotePathToLocal(remoteFilePath, remotePath, Path.GetTempPath());
// Download the file to the temporary folder
System.Diagnostics.Debug.WriteLine("Downloading file {0}...", fileInfo.FullName);
TransferOperationResult transferResult = session.GetFiles(remoteFilePath, localFilePath);
// Check if download succeeded
if (!transferResult.IsSuccess)
{
System.Diagnostics.Debug.WriteLine("Error downloading file {0}: {1}", fileInfo.FullName, transferResult.Failures[0].Message);
}
if (Path.GetExtension(fileInfo.Name) == ".zip")
{
using (ZipFile zip = ZipFile.Read(localFilePath))
{
string destinationPath = @"D:\Education - FrontEnd\videos";
zip.ExtractAll(destinationPath, ExtractExistingFileAction.OverwriteSilently);
}
}
// Determine the final destination path
string finalFilePath = Path.Combine(@"D:\Education - FrontEnd\videos", fileInfo.Name);
session.RemoveFiles(remoteFilePath);
}
session.Close();
}
}
catch (Exception ex)
{
// Log any errors
System.Diagnostics.Debug.WriteLine("Error occurred: " + ex.Message);
}