Add MLST command in the form of a Get method (#269)
* Add MLST command in the form of a Get method The `LIST` and `MLSD` commands are inefficient when the objective is to retrieve one single `Entry` for a known path, because the only way to get such an entry is to list the parent directory using a data connection. The `MLST` fixes this by allowing one single `Entry` to be returned using the control connection. The name `Get` was chosen because it is often used in conjunction with `List` as a mean to get one single entry. Signed-off-by: Thomas Hallgren <thomas@datawire.io> * Changes in response to code review: - Rename `Get` to `GetEntry` (because it returns an `*Entry`) - Add test-case for multiline response on the control connection - Fix issues with parsing the multiline response. Signed-off-by: Thomas Hallgren <thomas@datawire.io> * Add sample output from MLST to GetEntry comment. Signed-off-by: Thomas Hallgren <thomas@datawire.io> * Changes in response to code review: - Remove unused `time.Time` argument - Add struct labels to make `govet` happy Signed-off-by: Thomas Hallgren <thomas@datawire.io> * Remove time arg when calling parseNextRFC3659ListLine Signed-off-by: Thomas Hallgren <thomas@datawire.io> Signed-off-by: Thomas Hallgren <thomas@datawire.io>
This commit is contained in:
19
conn_test.go
19
conn_test.go
@@ -90,7 +90,7 @@ func (mock *ftpMock) listen() {
|
||||
// At least one command must have a multiline response
|
||||
switch cmdParts[0] {
|
||||
case "FEAT":
|
||||
features := "211-Features:\r\n FEAT\r\n PASV\r\n EPSV\r\n UTF8\r\n SIZE\r\n"
|
||||
features := "211-Features:\r\n FEAT\r\n PASV\r\n EPSV\r\n UTF8\r\n SIZE\r\n MLST\r\n"
|
||||
switch mock.modtime {
|
||||
case "std-time":
|
||||
features += " MDTM\r\n MFMT\r\n"
|
||||
@@ -178,6 +178,23 @@ func (mock *ftpMock) listen() {
|
||||
mock.dataConn.write([]byte("-rw-r--r-- 1 ftp wheel 0 Jan 29 10:29 lo\r\ntotal 1"))
|
||||
mock.printfLine("226 Transfer complete")
|
||||
mock.closeDataConn()
|
||||
case "MLSD":
|
||||
if mock.dataConn == nil {
|
||||
mock.printfLine("425 Unable to build data connection: Connection refused")
|
||||
break
|
||||
}
|
||||
|
||||
mock.dataConn.Wait()
|
||||
mock.printfLine("150 Opening data connection for file list")
|
||||
mock.dataConn.write([]byte("Type=file;Size=0;Modify=20201213202400; lo\r\n"))
|
||||
mock.printfLine("226 Transfer complete")
|
||||
mock.closeDataConn()
|
||||
case "MLST":
|
||||
if cmdParts[1] == "multiline-dir" {
|
||||
mock.printfLine("250-File data\r\n Type=dir;Size=0; multiline-dir\r\n Modify=20201213202400; multiline-dir\r\n250 End")
|
||||
} else {
|
||||
mock.printfLine("250-File data\r\n Type=file;Size=42;Modify=20201213202400; magic-file\r\n250 End")
|
||||
}
|
||||
case "NLST":
|
||||
if mock.dataConn == nil {
|
||||
mock.printfLine("425 Unable to build data connection: Connection refused")
|
||||
|
||||
Reference in New Issue
Block a user