From 190f39e8b20cb0f498212b6f1e1fe236c8cd98b7 Mon Sep 17 00:00:00 2001 From: Georg Wechslberger Date: Mon, 23 May 2022 12:36:17 +0200 Subject: [PATCH] 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 := " "