Try this from the code behind of a regular aspx file. The file uploads fine, but the code just stops at the sftp.Disconnect() call.
string fileContents = "sftp this text!";
Stream contentStream = new MemoryStream(ASCIIEncoding.Default.GetBytes(fileContents));
string filenameFormat = "filename_{0:yyyyMMdd_HHmm}.txt";
string filename = string.Format(filenameFormat, DateTime.Now);
bool fileUploaded = false;
using (SftpClient sftp = new SftpClient("sftp.MYDOMAIN.com", 5970, "MYUSERNAME", "MYPASSWORD"))
{
sftp.Connect();
sftp.UploadFile(contentStream, filename);
// calling disconnect kills everything - removing it just so the code will continue
try
{
sftp.Disconnect();
}
catch
{
}
// CODE NEVER GETS HERE
Response.Write("IT WORKED!");
}