title: Upload dynamically created XML file using SFTP guidance
body: <p>Currently I am generating an xml file for download using posted fields with the following code:</p>
  
  <pre><code>    string attachment = "attachment; filename=" + FileName + ".xml";
      Response.ClearContent();
      Response.ContentType = "application/xml";
      Response.AddHeader("content-disposition", attachment);
      Response.Write(Session["FileForDownload"]);
      Response.End();
  </code></pre>
  
  <p>This is working fine.</p>
  
  <p>However I want to sftp upload the generated file to a specified directory on a server.</p>
  
  <p>I have had success in connecting using ssh.net and have been able to create a new directory etc.</p>
  
  <p>My question is how can I generate the file and then sftp it using ssh.net?</p>
  
  <p>I've tried using a file stream with no success. I'm guessing the file needs to be temporarily stored and then retrieved for upload.</p>
  
  <p>This is my current code segment for the specified problem:</p>
  
  <pre><code>        SftpClient sftp = new SftpClient("host", "user", "pwd");
          sftp.Connect();
          sftp.ChangeDirectory("directory/");
          Stream fs = File.OpenRead(Server.MapPath(@"filetobeuploaded"));
          sftp.UploadFile(fs, Session["FileName"].ToString());
          sftp.Disconnect();
  </code></pre>
  
  <p>I recognize that there won't be a file already on the server to upload.</p>
  
  <p>Any help would be much appreciated as this is the final piece of the puzzle in my application.</p>
  
  <p>Cheers</p>