While uploading the file to Hostinger.com FTP server folder, I'm getting the following error:
System.Net.WebException: 'Unable to connect to the remote server'
Error occurs on this row:
Stream requestStream = request.GetRequestStream();
Please help me! Thanks!
//FTP Upload
string sourcefilepath;
string ftpurl = "ftp://IP/home/u323320256/domains/razidawakhana.com/public_html";
string ftpusername = "zikria"; // e.g. username
string ftppassword = "Yamankatita1@"; // e.g. password
string PureFileName = new FileInfo(file_name).Name;
String uploadUrl = String.Format("{0}/{1}/{2}", ftpurl, "PDPix", file_name);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uploadUrl);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(ftpusername, ftppassword);
request.Proxy = null;
request.KeepAlive = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(_mediaFile.Path);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
```