1

Closed

%datetime% macro does not supported for Remote File Name

description

%datetime% macro doesn’t work for Remote File Name when used in a string, example: companyname_%datetime%.txt. It produces the file name as is (with % signs and datetime as text). In other word the %datetime% variable is not set.
Additional information: Temp directory is used.
Additional try was made to add the name to Temp File Name as well as use only the %datetime%.txt file name (without the predicate string). Both attempts produced the same result.
Closed by

comments

wmmihaa wrote Oct 15, 2009 at 7:44 AM

%datatime% is not a supported macro. The adapter currently does only support %MessageID% and %SourceFileName%.

It's a small thing to add. Download the source code and open the Blogical.Adapters.Sftp.sln solution. In the Blogical.Shared.Adapters.Sftp project, open SftpTransmitProperties.cs, and go to line 340.
Update the ReplaceMacros to below (I haven't tested tihs code). This should give you two macros %DateTime% and %UniversalDateTime%.

Let me know how it works

private static string ReplaceMacros(IBaseMessage message, string uri)
{
if (uri.IndexOf("%MessageID%") > -1)
{
    Guid msgId = message.MessageID;

    uri = uri.Replace("%MessageID%", msgId.ToString());
}
if (uri.IndexOf("%SourceFileName%") > -1)
{
    string sourceFileName = string.Empty;
    try
    {
        string filePath = GetReceivedFileName(message);
        sourceFileName = Path.GetFileName(filePath);
    }
    catch 
    {
        throw new Exception("The %SourceFileName% macro can only be used with the " + Constants.SFTP_ADAPTER_PROPERTIES_NAMESPACE + " namespace.");
    }
    uri = uri.Replace("%SourceFileName%", sourceFileName);
}
if (uri.IndexOf("%DateTime%") > -1)
{
    string dateTime = DateTime.Now.ToString();

    uri = uri.Replace("%DateTime%", dateTime);
}
if (uri.IndexOf("%UniversalDateTime%") > -1)
{
    string dateTime = DateTime.Now.ToUniversalTime();

    uri = uri.Replace("%UniversalDateTime%", dateTime);
}

return uri;
}