From b70c76ed2824013b43e3e86d0a83bdd5781b0803 Mon Sep 17 00:00:00 2001 From: jlaffaye Date: Tue, 6 Sep 2011 00:02:01 +0200 Subject: [PATCH] More commands and their tests. Delete() MakeDir() RemoveDir() --- client_test.go | 15 +++++++++++++++ ftp.go | 27 ++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/client_test.go b/client_test.go index 8778488..dedc0b3 100644 --- a/client_test.go +++ b/client_test.go @@ -51,5 +51,20 @@ func TestConn(t *testing.T) { r.Close() } + err = c.Delete("tset") + if err != nil { + t.Error(err) + } + + err = c.MakeDir("mydir") + if err != nil { + t.Error(err) + } + + err = c.RemoveDir("mydir") + if err != nil { + t.Error(err) + } + c.Quit() } diff --git a/ftp.go b/ftp.go index 1c9af27..cde29ab 100644 --- a/ftp.go +++ b/ftp.go @@ -259,13 +259,34 @@ func (c *ServerConn) Rename(from, to string) os.Error { return err } +func (c *ServerConn) Delete(name string) os.Error { + _, err := c.conn.Cmd("DELE %s", name) + if err != nil { + return err + } + + _, _, err = c.conn.ReadCodeLine(StatusRequestedFileActionOK) + return err +} + func (c *ServerConn) MakeDir(name string) os.Error { - // todo - return nil + _, err := c.conn.Cmd("MKD %s", name) + if err != nil { + return err + } + + _, _, err = c.conn.ReadCodeLine(StatusPathCreated) + return err } func (c *ServerConn) RemoveDir(name string) os.Error { - return nil + _, err := c.conn.Cmd("RMD %s", name) + if err != nil { + return err + } + + _, _, err = c.conn.ReadCodeLine(StatusRequestedFileActionOK) + return err } // Sends a NOOP command. Usualy used to prevent timeouts.