Error in File Uploading using ASP.Net
Dear All
I am using following code snipped to upload file in SFTP. Its a console base application and working fine. File is uploaded in SFTP in a specific time.
public static void FileUploadSFTP(string sFileType)
{
// server credential configaration
string sHost = ConfigurationManager.AppSettings["hostname"].ToString();
string sUserName = ConfigurationManager.AppSettings["username"].ToString();
string sPassword = ConfigurationManager.AppSettings["password"].ToString();
int iPort = Convert.ToInt16(ConfigurationManager.AppSettings["port"].ToString());
string ReadFileLoc = Convert.ToString(ConfigurationManager.AppSettings["ReadFileLoc"]);
string uploadDirectory = Convert.ToString(ConfigurationManager.AppSettings["uploadDirectory"]);
string sFileName = "";
var host = sHost;
var port = iPort;
var username = sUserName;
var password = sPassword;
// path for file you want to upload
// var uploadFile = @"c:yourfilegoeshere.txt";
//select file name from the location D:\\DCC
sFileName = ReadFileLoc + getFileName(sFileType);
var uploadFile = sFileName;
try
{
using (var client = new SftpClient(host, port, username, password))
{
client.Connect();
// Change server directory
client.ChangeDirectory(uploadDirectory);
if (client.IsConnected)
{
Debug.WriteLine("I'm connected to the client");
Console.WriteLine("Connected to SFTP server");
CLog.Logger.Write(CLog.INFORMATION, "/CFileUpload: I'm connected to the client ");
using (var fileStream = new FileStream(uploadFile, FileMode.Open))
{
client.BufferSize = 4 * 1024; // bypass Payload error large files
//Upload file
client.UploadFile(fileStream, Path.GetFileName(uploadFile));
}
CLog.Logger.Write(CLog.EXCEPTION, "/CFileUpload: Uploaded to server " + sFileName);
}
else
{
Debug.WriteLine("I couldn't connect");
CLog.Logger.Write(CLog.EXCEPTION, "/CFileUpload: Cound not connect ");
}
}
}
catch (Exception exp)
{
CLog.Logger.Write(CLog.EXCEPTION, "/CFileUpload: Cound not connect " + exp.ToString());
}
}
I am getting following sometimes
This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server
Can you please help why how to resolve this issue.
Thanks in advance