diff --git a/client_test.go b/client_test.go index 63eea08..f2f8931 100644 --- a/client_test.go +++ b/client_test.go @@ -8,6 +8,7 @@ import ( const ( testData = "Just some text" + testDir = "mydir" ) func TestConn(t *testing.T) { @@ -61,15 +62,39 @@ func TestConn(t *testing.T) { t.Error(err) } - err = c.MakeDir("mydir") + err = c.MakeDir(testDir) if err != nil { t.Error(err) } - err = c.RemoveDir("mydir") + err = c.ChangeDir(testDir) + if err != nil { + t.Error(err) + } + + dir, err := c.CurrentDir() + if err != nil { + t.Error(err) + } else { + if dir != "/" + testDir { + t.Error("Wrong dir: " + dir) + } + } + + err = c.ChangeDirToParent() + if err != nil { + t.Error(err) + } + + err = c.RemoveDir(testDir) if err != nil { t.Error(err) } c.Quit() + + err = c.NoOp() + if err == nil { + t.Error("Expected error") + } } diff --git a/ftp.go b/ftp.go index b0f6979..1321bd4 100644 --- a/ftp.go +++ b/ftp.go @@ -188,6 +188,27 @@ func (c *ServerConn) ChangeDir(path string) os.Error { return err } +func (c *ServerConn) ChangeDirToParent() os.Error { + _, _, err := c.cmd(StatusRequestedFileActionOK, "CDUP") + return err +} + +func (c *ServerConn) CurrentDir() (string, os.Error) { + _, msg, err := c.cmd(StatusPathCreated, "PWD") + if err != nil { + return "", err + } + + start := strings.Index(msg, "\"") + end := strings.LastIndex(msg, "\"") + + if start == -1 || end == -1 { + return "", os.NewError("Unsuported PWD response format") + } + + return msg[start+1:end], nil +} + // Retrieves a remote file func (c *ServerConn) Retr(path string) (io.ReadCloser, os.Error) { conn, err := c.cmdDataConn("RETR %s", path)