How to implement the function of downloading all files from the X directory to the Y directory on ftp.
I have achieved that one file is being sent. But there are two problems:
1 In a directory a lot of files under the directory.
2 If the file already exists with the same name, it is necessary to overwrite the new file.
requestFTPUploader = (FtpWebRequest)WebRequest.Create("ftp://127.0.0.1/Destination/" + fileName); requestFTPUploader.Credentials = new NetworkCredential("user", "pass"); requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile; FileInfo fileInfo = new FileInfo(filepath); FileStream fileStream = fileInfo.OpenRead(); int bufferLength = 2048; byte[] buffer = new byte[bufferLength]; try { 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(); } catch (Exception exception) { Console.WriteLine(exception.Message.ToString()); } Console.WriteLine(fileName + "Uploaded"); Those. need a function with input parameters: user, pass, sourceDir, destinationDir. And the output is copied / replaced files to the server using the ftp protocol.