Uploading data on secure site

hi friends
i am having trouble with the Secure ftp site. i was not able to upload the files on the secure ftp site using my code. the code works good if the ftp site don't have the Secure SSI connection. then i have written a code which uses FtpWebRequest for uploading the data on secure ftp site. In this code i have one problem about the Certificates which should be issued in order to make it secure sit. i don't have that certificates so i have written a static method which will make the certification value as valid in any case. here is the code. hope it will help you guys

public bool SecureConnection(string UrlPath, string UserName, string Password,string command,string filePath,string fileName)
//String serverUri = "ftp://ftpsite.com/folder1/Test";
if (command.Equals("UF"))
UrlPath = UrlPath + "//" + fileName;
//String serverUri =UrlPath;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UrlPath);
//request.Credentials = new NetworkCredential("username", "password");
request.Credentials = new NetworkCredential(UserName, Password);
request.UsePassive = true;
request.EnableSsl = true;
switch (command)
case "MD":
request.Method = WebRequestMethods.Ftp.MakeDirectory;
case "UF":
request.Method = WebRequestMethods.Ftp.UploadFile;
StreamReader sourceStream = new StreamReader(filePath);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
request.ContentLength = fileContents.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
catch (Exception _exp)
return false;
return true;

public static bool ValidateServerCertificate(object sender,X509Certificate certificate, X509Chain chain,SslPolicyErrors sslPolicyErrors)
return true;


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: