What I'm trying to do is upload a website using FTP in C # (C Sharp). Therefore, I need to upload all files and folders to a folder, preserving its structure. I use this FTP class: http://www.codeproject.com/Tips/443588/Simple-Csharp-FTP-Class for the actual download.
I came to the conclusion that I need to write a recursive method that goes through each subdirectory of the main directory and loads all the files and folders into it. This should make an exact copy of my FTP folder. The problem is ... I donβt know how to write such a method. I previously wrote recursive methods, but I'm new to the FTP part.
This is what I still have:
private void recursiveDirectory(string directoryPath) { string[] filePaths = null; string[] subDirectories = null; filePaths = Directory.GetFiles(directoryPath, "*.*"); subDirectories = Directory.GetDirectories(directoryPath); if (filePaths != null && subDirectories != null) { foreach (string directory in subDirectories) { ftpClient.createDirectory(directory); } foreach (string file in filePaths) { ftpClient.upload(Path.GetDirectoryName(directoryPath), file); } } }
But that is far from all, and I do not know how to proceed. I'm sure more than I need to know this! Thanks in advance.
Oh and ... It would be nice if he reported on his progress too :) (I use the progress bar)
EDIT: Perhaps it was unclear ... How to download a directory, including all subdirectories and files from FTP?
c # directory upload recursion ftp
Crashproofcode
source share