I want to track communication while connecting to SFTP,durign upload/download etc.
where should i et the code to log the communication from client to server via Rebex in the excusing code to get the communication happening.
// start logging to a file
sftp.LogWriter = new Rebex.FileLogWriter(@"C:\MyData\log.txt");
Existing cede
Connectivity Code
// create an SFTP object
var sftp = new Rebex.Net.Sftp();
Download code
#region SFTPDownload
private bool SFTPDownload(string FileType, string FileName)
{
string LocalPath = GetFilePath(FileType);
try
{
ExtendedLogger.Log("Downloading SFTP file: " + FileName + " Started!", 4, "SFTP_Download");
// Common.WriteLogService(" Downloading SFTP file: " + FileName + " Started!","",false);
ConnectSftp(ref dSftp);
if (!(File.Exists(LocalPath + FileName) == true && File.ReadAllBytes(LocalPath + FileName).Length > 0))
{
try
{
dSftp.GetFile(GetServerFilePath(FileType).ToString() + "//" + FileName, LocalPath + FileName);
ExtendedLogger.Log("Downloading SFTP file: " + FileName + " Finished!", 4, "SFTP_Download");
//Common.WriteLogService(" Downloading SFTP file: " + FileName + " Finished!", "", false);
}
catch (Exception ex)
{
Common.WriteLogService(" Downloading SFTP file: " + FileName + " Failed!", "", false);
Common.WriteLogService(ex.Message,ex.StackTrace,true);
}
}
else
{
Common.WriteLogService(" SFTP file: " + FileName + " downloaded already !", "", false);
}
return true;
}
catch (Exception ex)
{
Common.WriteLogService(" Downloading SFTP file: " + FileName + " Error:" + ex.Message,ex.StackTrace,true);
if (File.ReadAllBytes(LocalPath + FileName).Length <= 0)
{
try
{
dSftp.GetFile(GetServerFilePath(FileType).ToString() + "//OLD//" +FileName, LocalPath + FileName);
return true;
}
catch
{
//dSftp.Disconnect();commented by aswathy vm for SFTP Download issue after Server Upgrade - 17112020
return false;
}
}
else
{
//dSftp.Disconnect();commented by aswathy vm for SFTP Download issue after Server Upgrade - 17112020
return false;
}
}
}
#endregion