Joao Racchetti

Joao Racchetti

  • NA
  • 5
  • 1.2k

FTP UPLOAD

Jan 28 2014 9:54 AM
i have this code to upload a file to a ftp server, but i wanna upload one more file, how can i do this? sorry about the bad english, ia'm brazilian.
{
                string localPath = @"log\";
                string fileName = hora.Text + ".temp";

                FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create("ftp://IP/" + boxLigas.Text + "/" + txtMatch.Text + "/" + nick.Text + "/" + fileName);
                requestFTPUploader.Credentials = new NetworkCredential("login", "pass");
                requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile;

                FileInfo fileInfo = new FileInfo(localPath + fileName);
                FileStream fileStream = fileInfo.OpenRead();

                int bufferLength = 2048;
                byte[] buffer = new byte[bufferLength];

                Stream uploadStream = requestFTPUploader.GetRequestStream();
                int contentLength = fileStream.Read(buffer, 0, bufferLength);

                while (contentLength != 0)
                {
                    uploadStream.Write(buffer, 0, contentLength);
                    contentLength = fileStream.Read(buffer, 0, bufferLength);
                }

                uploadStream.Close();
                fileStream.Close();
                 

                requestFTPUploader = null;
            }