Upload to SFTP results in files of 0 byte length....

Aug 16, 2013 at 9:07 AM
Edited Aug 16, 2013 at 9:07 AM
I'm trying to upload some XML files (1 - 20K in size) from my local server to a SFTP server. The upload works - but the resulting files are 0 bytes long in the end.....

Any idea why?? Is there something missing from my code? Do I need to "flush" the contents to the SFTP server to make sure it's written properly?
public void UploadFile(Stream inputStream, string remoteDirectory)
{
   string hostname = "....";  // from config
   string username = "....";  // from config

   string internalPath = "..."; // internal path to embedded private key file
   Stream idStream = Assembly.GetEntryAssembly().GetManifestResourceStream(internalPath);

   // set up private key file authentication
   var keyFiles = new[] { new PrivateKeyFile(idStream) };
   var methods = new List<AuthenticationMethod> { new PrivateKeyAuthenticationMethod(username, keyFiles) };

   // copy input stream into memory stream
   MemoryStream memStm = new MemoryStream();
   inputStream.CopyTo(memStm);

   memStm.Seek(0, SeekOrigin.Begin);

   // setup connection info
   var con = new ConnectionInfo(hostname, username, methods.ToArray());

   // instantiate SftpClient, connect, change directory, upload file
   using (SftpClient client = new SftpClient(con))
   {
       client.Connect();
       client.ChangeDirectory(remoteDirectory);
       client.UploadFile(memStm, filename);
       client.Disconnect();
   }
}