Skip to content

Commit

Permalink
feat: add 'mkdir -p' support
Browse files Browse the repository at this point in the history
  • Loading branch information
lazywhite committed Jun 7, 2023
1 parent 2c2aa37 commit d3dd408
Showing 1 changed file with 35 additions and 0 deletions.
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

0 comments on commit d3dd408

Please sign in to comment.