jlaffaye / ftp

FTP client package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing a directory recursively affects the current working directoty

worblehat opened this issue · comments

Describe the bug
After deleting a directory recursively with RemoveDirRecur the current working directory will be the parent directory of the deleted directory.

To Reproduce

package main

import (
	"log"

	"github.com/jlaffaye/ftp"
)

func main() {
	
        var opts []ftp.DialOption
	opts = append(opts, ftp.DialWithDebugOutput(log.Writer()))

	con, err := ftp.Dial("192.168.2.232:21", opts...)
	if err != nil {
		log.Println(err)
		return
	}

	if err := con.Login("root", "root"); err != nil {
		log.Println(err)
		return
	}

	cwd, err := con.CurrentDir()
	if err != nil {
		log.Println(err)
		return
	}

	log.Println("Current working directory:", cwd)

	err = con.RemoveDirRecur("A/B/C")
	if err != nil {
		log.Println(err)
		return
	}

	cwd, err = con.CurrentDir()
	if err != nil {
		log.Println(err)
		return
	}
	log.Println("Current working directory:", cwd)
}

Expected behavior
I would expect the working directory to be reset to what it was before calling RemoveDirRecur.

Output

Current working directory: /
Current working directory: /A/B

Debug Output

USER root
331 User name ok, need password
PASS root
230 Login successful, Priv=0x001F
FEAT
211-Features:
 USER PASS SYST QUIT FEAT OPTS TYPE PORT
 PASV PWD  CWD  CDUP MKD  RMD  RETR STOR
 APPE DELE RNFR RNTO MDTM SIZE LIST STAT
 UTF8 REST MODE STRU XPWD
211 Features done
TYPE I
200 Switching to BINARY mode
OPTS UTF8 ON
200 Always in UTF8 mode
PWD
257 "/"
Current working directory: /
CWD A/B/C
250 Success!
PWD
257 "/A/B/C"
EPSV
500 unknown command
PASV
227 Switched to passive mode (192,168,2,232,193,45)
LIST /A/B/C
150 Opening data connection
226 Transfer complete #1010
CWD /A/B/C/D
250 Success!
PWD
257 "/A/B/C/D"
PASV
227 Switched to passive mode (192,168,2,232,193,46)
LIST /A/B/C/D
150 Opening data connection
226 Transfer complete #1010
DELE foo
250 Success!
CDUP
250 Success!
RMD /A/B/C/D
250 Success!
CDUP
250 Success!
RMD /A/B/C
250 Success!
PWD
257 "/A/B"
Current working directory: /A/B
commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.