the Ftp object's method Rename is not capable of automatically creating directory /Archive/demo/new/2013/Feb/021613/ if it does not exist. Also if /test/demo/new/1.tiff is not found on the server the above reported exception is reported.
Please try EnhancedFileMove method below which handles these situations automatically.
Ftp ftp = new Ftp();
//Connect & Login
EnhancedFileMove(ftp, "test/1.tiff", "Archive/2013/Feb/021613", "1.tiff", '/');
ftp.Disconnect();
private void EnhancedFileMove(Ftp ftp, string fromFilePath, string toFilePath, string toFile, char delimiter)
{
if(!ftp.FileExists(fromFilePath))
throw new ApplicationException(string.Format("File {0} does not exist.", fromFilePath));
if (!ftp.DirectoryExists(toFilePath))
{
CreateDirectory(ftp, toFilePath, delimiter);
}
ftp.Rename(fromFilePath, string.Format("{0}{1}{2}", toFilePath, delimiter, toFile));
}
private void CreateDirectory(Ftp ftp, string remoteDirectory, char delimiter)
{
if (remoteDirectory.IndexOf(delimiter) <= 0)
{
ftp.CreateDirectory(remoteDirectory);
}
else
{
int index = remoteDirectory.LastIndexOf(delimiter);
string path = remoteDirectory.Substring(0, index);
string dir = remoteDirectory.Substring(index + 1);
//create recursively path
CreateDirectory(ftp, path, delimiter);
ftp.CreateDirectory(remoteDirectory);
}
}