title: Modified date time changes when moving a file from Windows to UNIX server using SSH.NET
body: <p>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:</p>
  
  <ol>
  <li><p>In the UNIX server directory <strong>if the file to be copied <em>does not exist</em></strong>, then <strong>the modified datetime of the file when it is copied to the UNIX server changes to the copied datetime</strong>? Is this correct because the modified datetime is not supposed to change right?</p></li>
  <li><p>In the UNIX Server directory <strong>if the file to be copied <em>already exists</em></strong>, then on copying the same file which gets replaced in the UNIX Server path <strong>the modified datetime of the file does not change</strong>!</p></li>
  </ol>
  
  <p>I am confused with this modified datetime as I have read in this <a href="https://stackoverflow.com/questions/36638993/ssh-net-is-it-possible-to-upload-files-using-sftp-and-preserve-the-file-dates-f">post</a> that SSH.NET does it wrongly, is this supposed to be right?</p>
  
  <p>For those of you asking to provide code, here goes:</p>
  
  <pre><code>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;
      }
  }
  </code></pre>