Hi,
I am trying files to remote directory. The source folder is "Data" (relative to current directory) and the destination is \rcmprod\.
I have attached the log for the session.
here is the code iam using:
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSFTP"]) ? Protocol.Sftp : Protocol.Ftp, //If SFTP is configured then use that or else use FTP ; in PROD it should be SFTP
HostName = ConfigurationManager.AppSettings["SFTPHost"],
UserName = ConfigurationManager.AppSettings["SFTPUserName"],
Password = ConfigurationManager.AppSettings["SFTPPassword"],
SshHostKeyFingerprint = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSFTP"]) ? ConfigurationManager.AppSettings["SFTPHostKey"] : null
};
using (Session session = new Session())
{
session.SessionLogPath = GetSessionLogPath();
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = session.PutFiles(ConfigurationManager.AppSettings["SFTPSourceFolder"], ConfigurationManager.AppSettings["SFTPRemoteFolder"], false, transferOptions);
//rcmtest is the remote folder at the root level
// Throw on any error
transferResult.Check();
// Print results and Archive data file
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
NLog.LogManager.GetCurrentClassLogger().Trace("Upload of {0} succeeded", transfer.FileName);
ArchiveData(transfer.FileName);
}
}