Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 'mkdir -p' support #334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,41 @@ func (c *ServerConn) MakeDir(path string) error {
return err
}

// MakeDirRecur create a folder recursively using
// MakeDir and ChangeDir
func (c *ServerConn) MakeDirRecur(folder string) error {
// save current dir path
currentDir, err := c.CurrentDir()
if err != nil {
return err
}
dirs := strings.Split(folder, "/")
for _, dir := range dirs {
if dir == "" {
continue
}
// check if dir exists
err := c.ChangeDir(dir)
if err == nil {
continue
}
err = c.MakeDir(dir)
if err != nil {
return err
}
err = c.ChangeDir(dir)
if err != nil {
return err
}
}
// move to origin dir
err = c.ChangeDir(currentDir)
if err != nil {
return err
}
return nil
}

// RemoveDir issues a RMD FTP command to remove the specified directory from
// the remote FTP server.
func (c *ServerConn) RemoveDir(path string) error {
Expand Down