Como puedo subir mis carpetas a mi servidor FTP y asi hay subcarpetas que tambien se suban junto con todos los archivos que tengan dentro.
Tengo el siguiente codigo y esto solo me sube el nombre de la carpeta y los archivos que hay dentro. Si hay una carpeta dentro o mas no se suben.
protected static void UploadFile(string FilePath, string RemotePath, string Login, string Password, string fileName)
{
try
{
using (FileStream fs = File.Open(FilePath, FileMode.OpenOrCreate, FileAccess.Read))
{
string url = RemotePath + "/Backup-PC-Directoy/" + fileName;
FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(url);
ftp.Credentials = new NetworkCredential(Login, Password);
ftp.KeepAlive = false;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.UseBinary = true;
ftp.ContentLength = fs.Length;
ftp.Proxy = null;
byte[] buff = new byte[fs.Length];
fs.Read(buff, 0, buff.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buff, 0, buff.Length);
ftpstream.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}