mike Delvotti

mike Delvotti

  • NA
  • 262
  • 0

Move files in folder one by one and rename

Jul 24 2014 8:39 AM

Guys,

This may be a bit of a long shot, but my code below is working fine for moving one file to an ftp location, what I would ideally like to do is upload all the files in the folder '@c:\test' one by one and rename them according to the value on label1,text

So in theory I don't want to throw all files up in one lump but rather loop through each file one by one and rename with each file according to the value in the label1,text

will this have to be done on a new ftp request for each file? can the below be adapted?

 FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftpserver" + "label1.text");

   request.Method = WebRequestMethods.Ftp.UploadFile;

   request.Credentials = new NetworkCredential("username", "password");



   Image img = Image.FromFile(@"C:\Winter.jpg"); // notice single back-slash

   MemoryStream ms = new MemoryStream();

   img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

   byte[] fileContents = ms.ToArray();

   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();


Answers (2)