munirulislam-6123 avatar image
0 Votes"
munirulislam-6123 asked YihuiSun-MSFT edited

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;


             using (var client = new SftpClient(host, port, username, password))
                 // Change server directory
                 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);
                     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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @munirulislam-6123,
It means that the DNS lookup of the sftp server name cannot be resolved, and the IP address cannot be determined. It could be that the DNS server of the remote site is down, or the domain itself is misconfigured and is pointing to a non-existent/unreachable DNS server.You can try to connect again.

0 Votes 0 ·

0 Answers