I am using SSH.NET in my C# application to copy files from a Windows to a UNIX server, I have a few scenarios for this:
In the UNIX server directory if the file to be copied does not exist, then the modified datetime of the file when it is copied to the UNIX server changes to the copied datetime? Is this correct because the modified datetime is not supposed to change right?
In the UNIX Server directory if the file to be copied already exists, then on copying the same file which gets replaced in the UNIX Server path the modified datetime of the file does not change!
I am confused with this modified datetime as I have read in this post that SSH.NET does it wrongly, is this supposed to be right?
For those of you asking to provide code, here goes:
private static int UploadFileToSFTP (string localFileFullPath, string uploadPath)
{
try
{
Log.Debug("Inside Utilities.UploadFileToSFTP() with localFileFullPath=" + localFileFullPath + ", and remoteUploadPath=" + uploadPath);
Log.Debug("Uploading File : " + uploadPath);
using (FileStream fs = new FileStream(localFileFullPath, FileMode.Open))
{
Log.Debug("Checking if path: " + Path.GetDirectoryName(uploadPath).Replace("\\", "/") + " already exists");
if (!IsDirectoryExists(Path.GetDirectoryName(uploadPath).Replace("\\", "/")))
{
Log.Debug(Path.GetDirectoryName(uploadPath).Replace("\\", "/") + " | Directory does not exist, creating!");
sftpClient.CreateDirectory(Path.GetDirectoryName(uploadPath).Replace("\\", "/"));
}
else
{
Log.Debug(Path.GetDirectoryName(uploadPath).Replace("\\", "/") + " | Directory already exists!");
}
Log.Debug("Checking if file: " + uploadPath + " already exists");
if (sftpClient.Exists(uploadPath))
{
Log.Debug(uploadPath + " | File Already exists in the Server");
}
else
{
Log.Debug(uploadPath + " | File Does not exist in the Server!");
}
sftpClient.BufferSize = 1024;
sftpClient.UploadFile(fs, uploadPath);
fs.Close();
}
return 1;
}
catch (Exception exception)
{
Log.Error("Error in Utilities.UploadFileToSFTP(): ", exception);
return 0;
}
}