kiran vontela

kiran vontela

  • NA
  • 50
  • 11.8k

upload text file to 5 ftp servers

Jul 24 2014 11:08 AM
 I am newbie to c# and working on this code to upload single text file (csv file) to 5 (cameras) ftp locations. I am working on this code it works well for one site but how can i do that for 4 other (cameras) ftp locations.how to pass mutliple ftp adddress in an array
private void button1_Click(object sender, EventArgs e)         {            UploadBlacklistFile(string ftpServerUrl,string filename);          }              void UploadBlacklistFile(string ftpServerUrl,string filename)             {             Boolean ftpMode = true;              //// Get the object used to communicate with the server.             //FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://158.125.161.83");             //request.Method = WebRequestMethods.Ftp.UploadFileWithUniqueName;              //// This example assumes the FTP site uses anonymous logon.             //request.Credentials = new NetworkCredential("superuser", "superuser");              if (ftpMode == true)             {                 request.KeepAlive = false;             }             // Copy the contents of the file to the request stream.             StreamReader sourceStream = new StreamReader("C://blacklist/ticketsblacklist.csv");             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);              response.Close();      string [] ftpaddress = ({"100.100.100.85","parm","parm"};{"101.101.101.85","parm1","parm1"})      foreach(string addr in ftpaddress) {     uploadFile(addr, @"C:/blacklist/ticketsblacklist.csv");         }     } }