0 votes
by (120 points)

When I send a file to FTP is there a way to have the Rebex component to automatically create directories on server if they do not exist (similarly to what the BatchUpload does?)

Applies to: Rebex FTP/SSL

1 Answer

+2 votes
by (144k points)

This is not supported by the component itself, but can be easily implemented. The following method should do what you need. It takes two arguments - an instance of Ftp object (connected and authenticated) and the path:

public static void CreatePath(Ftp ftp, string path)
    string[] parts = path.Trim('/').Split('/');
    if (parts.Length == 0)
        throw new ArgumentException("Invalid path.", "path");

    if (path.StartsWith("/"))
        path = "/";
        path = "";

    string current = ftp.GetCurrentDirectory();
    for (int i = 0; i < parts.Length; i++)
        path += parts[i];
        ftp.SendCommand("CWD " + path);
        FtpResponse response = ftp.ReadResponse();
        if (response.Group == 5)
        path += "/";

If you prefer VB.NET, please let me know.