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?)

asked 09 Feb '10, 10:31

Andrea's gravatar image

Andrea
161
accept rate: 0%

edited 11 Mar '10, 19:52

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310


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 = "/";
    else
        path = "";

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

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

link

answered 09 Feb '10, 14:25

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×152
×6

Asked: 09 Feb '10, 10:31

Seen: 1,024 times

Last updated: 11 Mar '10, 19:52