I had to make it 2 different operations first one creates the Excel file and then this, uploads existing file and remove it afterward.
Using a library called WinSCP
I couldn't find any library that supports 90s Encryptions like Implicit FTP over TLS and streaming API at the same time. So there was no way for me to directly create the excel file on the server but to temporary create it locally to copy it over and remove it at the same time, it is almost the same thing I get the same result. And here's solution for doing it
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = @"xx.xx.x.x",
UserName = "xxxx",
Password = "xxxxxx",
PortNumber = xxxx,
FtpSecure = FtpSecure.Implicit, //Encryption protocol
GiveUpSecurityAndAcceptAnyTlsHostCertificate = true // Accepts any certificate
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
// Copy's Existing file to Connected server and delets the old one.
// change by replace "true" with "false".
transferResult =
session.PutFiles(
ExistingPath, "/ScheduleJobs/" + RemotePath, true, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
Console.ReadLine();
}
}
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
}