From 190f39e8b20cb0f498212b6f1e1fe236c8cd98b7 Mon Sep 17 00:00:00 2001 From: Georg Wechslberger Date: Mon, 23 May 2022 12:36:17 +0200 Subject: [PATCH 1/2] feat: support TYPE command --- ftp.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ftp.go b/ftp.go index 27324a5..a908bdc 100644 --- a/ftp.go +++ b/ftp.go @@ -28,6 +28,15 @@ const ( EntryTypeLink ) +// TransferType denotes the formats for transfering Entries. +type TransferType string + +// The different transfer types +const ( + TransferTypeImage = "I" + TransferTypeASCII = "A" +) + // Time format used by the MDTM and MFMT commands const timeFormat = "20060102150405" @@ -340,7 +349,7 @@ func (c *ServerConn) Login(user, password string) error { c.mdtmCanWrite = c.mdtmSupported && c.options.writingMDTM // Switch to binary mode - if _, _, err = c.cmd(StatusCommandOK, "TYPE I"); err != nil { + if err = c.Type(TransferTypeImage); err != nil { return err } @@ -580,6 +589,12 @@ func (c *ServerConn) cmdDataConnFrom(offset uint64, format string, args ...inter return conn, nil } +// Type switches the transfer mode for the connection. +func (c *ServerConn) Type(transferType TransferType) (err error) { + _, _, err = c.cmd(StatusCommandOK, "TYPE "+string(transferType)) + return err +} + // NameList issues an NLST FTP command. func (c *ServerConn) NameList(path string) (entries []string, err error) { space := " " From b29e1f6c6292e9d9100365cee88e799d34294fc4 Mon Sep 17 00:00:00 2001 From: Georg Wechslberger Date: Mon, 23 May 2022 17:21:05 +0200 Subject: [PATCH 2/2] refactor: rename TransferTypeImage to TransferTypeBinary --- ftp.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ftp.go b/ftp.go index a908bdc..abe944f 100644 --- a/ftp.go +++ b/ftp.go @@ -33,8 +33,8 @@ type TransferType string // The different transfer types const ( - TransferTypeImage = "I" - TransferTypeASCII = "A" + TransferTypeBinary = "I" + TransferTypeASCII = "A" ) // Time format used by the MDTM and MFMT commands @@ -349,7 +349,7 @@ func (c *ServerConn) Login(user, password string) error { c.mdtmCanWrite = c.mdtmSupported && c.options.writingMDTM // Switch to binary mode - if err = c.Type(TransferTypeImage); err != nil { + if err = c.Type(TransferTypeBinary); err != nil { return err }