We are using SftpClient class from Renci.SshNet namespace. Using SftpClient Class, we are trying to connect to a SFTP location. But an error is coming intermittently with description “Message type 96 is not valid in the current context”. I have seen questions similar to this, but not where “Message type 96” is mentioned. That’s why created a new thread for this. The error is coming from the code “client.Connect()”.Here is the code
using (var client = new SftpClient(payload["sftpUrl"].ToString(), payload["sftpUserName"].ToString(), payload["sftpPassword"].ToString()))
{
client.Connect();
foreach (var creditMemoFile in groupedCreditMemoFile)
{
var fileName = string.Format(payload["fileNameFormat"].ToString(), creditMemoFile[0].LegalEntity.ToString());
var csv = new StringBuilder();
csv.Append(creditMemoHeaders + "rn");
foreach (var row in creditMemoFile)
{
var newLine = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}{8}", row.OrderNumber.ToString(), row.Account,
row.ModifiedDate, row.LegalEntity, row.ClaimId, row.SalesQty, row.ItemId, row.ApprovedAmount, "rn");
csv.Append(newLine);
}
client.WriteAllText(payload["outputFilePath"].ToString() + string.Concat(fileName, DateTime.UtcNow.Date.ToString(payload["fileNameDateFormat"].ToString()), @".csv"), csv.ToString());
}
}