secsy / goftp

FTP client for golang
MIT License
177 stars 96 forks source link

add function to create directories recursively #23

Closed GlenDC closed 6 years ago

GlenDC commented 7 years ago

The function would be added as a method to the client and could have the following signature:

func (c *Client) MkdirRecursive(path string) (string, error)

// an alternative name could be `Mkdirs`, I leave this up to you

I don't think it should ever fail if a directory already exist (no matter where in the path), but I'm open to suggestions on this part.

I'm proposing it as it seems like a generic enough feature that others might want it as well. If this seems like something you agree would be a nice addition to the lib than I wouldn't mind putting development time in to get this added as a PR.

For now I already have a first version ready, which probably has plenty of room for improvement, but it might help give the idea and show my willingness to help get this feature in this library. You can find an initial (perhaps prototype?) version I made for my project at: https://github.com/zero-os/0-Disk/blob/196c18e382ae839c9fee9bca457bea49890539ce/nbd/ardb/backup/storage_ftp.go#L214-L260

muirmanders commented 7 years ago

Thank you for the suggestion. I want to keep the client API simple (i.e. close correspondence to the actual FTP commands). I would be open to a separate package "ftputil" (a la "ioutil") or similar that has these kinds of useful functions. The signature could be something like MkdirAll(*goftp.Client, string) (string, error) ("MkdirAll" is consistent w/ std lib naming).

GlenDC commented 7 years ago

That sounds like a reasonable approach to me. In the course of the next week I'll try to allocate some time and open a PR for it, so we can take it from there.

muirmanders commented 6 years ago

Closing due to inactivity. Please re-open if you want to keep working on this.