1
Answer

Read file using FTP

Archana Patil

Archana Patil

12y
2.9k
1
Hi,

My code is

FtpWebRequest strRequest = (FtpWebRequest)WebRequest.Create(myUrl);
  strRequest.Credentials = new NetworkCredential(username,PWD);
  strRequest.UsePassive = true;
  strRequest.UseBinary = true;
  strRequest.KeepAlive = true;



  FtpWebResponse Response = (FtpWebResponse)strRequest.GetResponse();
  Stream ResponseStream = Response.GetResponseStream();
  StreamReader Reader = new StreamReader(ResponseStream);
 
  string strt = "";
  string str = null;
  while ((str = Reader.ReadLine()) != null)
  {
  string[] str1 = str.Split('|');

  string dts = str1[6].ToString();

  dts = dts.Substring(0, str1[6].Length - 9);

  string tm = str1[6].ToString();

  tm = tm.Substring(11);


  strt = str1[0] + "," + str1[1] + "," + str1[2] + "," + str1[3] + "," + str1[4] + "," + str1[5] + "," + dts + "," + tm + "," + str1[7] + "," + str1[8] + "," + str1[9] + "," + str1[10] + "," + str1[11] + "," + str1[12];

  TestMethod(strt);
  }

  Response.Close();
  ResponseStream.Close();
  Reader.Close();

When i run this code locally its working properly but when i put it on live
I am getting error "The remote server returned an error: 227 Entering Passive Mode (203,197,64,8,16,33). . ". in reading CSV file from server.I am using .net 4.0
please help

Thanks,
Archana

Answers (1)