Dear Prakash,
here is the sample code for uploading directory.
static Aspose.Network.Ftp.FtpClient client;
static void Main(string[] args)
{
client = new Aspose.Network.Ftp.FtpClient("ftp://www.yourdomain.com", "user", "password");
client.Connect(true);
UploadFolder(@"c:\folder", "remote", true);
}
public void UploadFolder(string localFolderPath, string remotePath, bool recursive)
{
if (null == localFolderPath)//check param
{
throw new ArgumentNullException("localFolderPath");
}
if (0 >= localFolderPath.Length)//check param
{
throw new ArgumentException("localFolderPath should not be empty.");
}
if (null == remotePath)//check param
{
throw new ArgumentNullException("remotePath");
}
DirectoryInfo dir = new DirectoryInfo(localFolderPath);
Exception inner = null;
UploadFilesInFolder(remotePath, dir, out inner);//upload files in the local folder
if (inner != null)//if we get exception, throw it
throw inner;
if (recursive)//if recursive continue to upload subfolders
{
remotePath = string.Concat(remotePath, "/", dir.Name);
DirectoryInfo[] directories = dir.GetDirectories();
if (directories != null && directories.Length > 0)
{
foreach (DirectoryInfo d in directories)
{
UploadFolder(d.FullName, remotePath, recursive);
}
}
}
}
private void UploadFilesInFolder(string remotePath, DirectoryInfo dir, out Exception inner)
{
try
{
inner = null;
string destPath = string.Concat(remotePath, "/", dir.Name);
System.Diagnostics.Debug.WriteLine(destPath);
//create a new directory on the remote server.
client.MakeDirectory(destPath);
FileInfo[] files = dir.GetFiles();
if (files != null && files.Length > 0)
{
foreach (FileInfo file in files)
{
System.Diagnostics.Debug.WriteLine(file.FullName);
//upload the files
client.Upload(file.FullName, destPath + "/" + file.Name);
}
}
}
catch (Exception ex)
{
inner = ex;
}
}