title: Simple Application To Transfer File From Localhost To SFTP
body: <p>I'm looking to create a simple desktop application that transfers a file from my local machine to an SFTP location.</p>
  
  <p>I have attempted the below, which transfers a file from my local machine to another location on my machine.. But struggling on how to transfer to an SFTP location, which uses a username and password.</p>
  
  <pre><code>namespace SFTPTranfer
  {
  class Program
  {
      static void Main(string[] args)
      {
          try
          {
              string fileToCopy = "C:\\TransferFileTest.txt";
              string newLocation = "C:\\copiedFiles\\copiedTransferFileTest.txt";
              //string newLocation = "https:\\URL\folder1\folder2";
              //string URLUser = "Test";
              //string URLPassword = "Password";
              string folderLocation = "C:\\copiedFiles";
  
              if (System.IO.Directory.Exists(folderLocation))
              {
                  if (System.IO.File.Exists(fileToCopy))
                  {
                      System.IO.File.Copy(fileToCopy, newLocation, true);
                      Console.WriteLine("File copied.");
                  }
                  else
                  {
                      Console.WriteLine("No such file.");
                  }
              }
              else
              {
                  Console.WriteLine("No such directory.");
              }
  
          }
          catch (Exception ex)
          {
              Console.Write("Error : " + ex.Message);
          }
  
          Console.WriteLine("Done.");
          Console.ReadLine();
      }
  }
  }
  </code></pre>
  
  <p>Any help appreciated</p>
  
  <p><em>UPDATE</em></p>
  
  <p>Decided to use this approach: <a href="http://blog.deltacode.be/2012/01/05/uploading-a-file-using-sftp-in-c-sharp/" rel="nofollow">http://blog.deltacode.be/2012/01/05/uploading-a-file-using-sftp-in-c-sharp/</a></p>
  
  <p>Works fine.</p>