diff --git a/asciiconverter.go b/asciiconverter.go index ec5d0cb7..308c694c 100644 --- a/asciiconverter.go +++ b/asciiconverter.go @@ -37,7 +37,7 @@ func (c *asciiConverter) Read(p []byte) (n int, err error) { } else { data, _, err = c.reader.ReadLine() if err != nil { - return + return -1, err } } @@ -64,7 +64,7 @@ func (c *asciiConverter) Read(p []byte) (n int, err error) { // client transfers it in ASCII mode err = c.reader.UnreadByte() if err != nil { - return + return -1, err } lastByte, err := c.reader.ReadByte() diff --git a/client_handler.go b/client_handler.go index ddf8f248..18f22e12 100644 --- a/client_handler.go +++ b/client_handler.go @@ -574,7 +574,7 @@ func (c *clientHandler) writeLine(line string) { c.logger.Debug("Sending answer", "line", line) } - if _, err := c.writer.WriteString(fmt.Sprintf("%s\r\n", line)); err != nil { + if _, err := fmt.Fprintf(c.writer, "%s\r\n", line); err != nil { c.logger.Warn( "Answer couldn't be sent", "line", line, diff --git a/client_handler_test.go b/client_handler_test.go index fce99cc2..4fb26681 100644 --- a/client_handler_test.go +++ b/client_handler_test.go @@ -239,6 +239,7 @@ func TestClientContextConcurrency(t *testing.T) { for counter < 100 { _, err := c.Getwd() assert.NoError(t, err) + counter++ } @@ -350,11 +351,11 @@ type testNetConn struct { remoteAddr net.Addr } -func (*testNetConn) Read(b []byte) (n int, err error) { +func (*testNetConn) Read(_ []byte) (n int, err error) { return } -func (*testNetConn) Write(b []byte) (n int, err error) { +func (*testNetConn) Write(_ []byte) (n int, err error) { return } @@ -370,15 +371,15 @@ func (c *testNetConn) RemoteAddr() net.Addr { return c.remoteAddr } -func (*testNetConn) SetDeadline(t time.Time) error { +func (*testNetConn) SetDeadline(_ time.Time) error { return nil } -func (*testNetConn) SetReadDeadline(t time.Time) error { +func (*testNetConn) SetReadDeadline(_ time.Time) error { return nil } -func (*testNetConn) SetWriteDeadline(t time.Time) error { +func (*testNetConn) SetWriteDeadline(_ time.Time) error { return nil } diff --git a/control_unix.go b/control_unix.go index 752a2973..6ab45323 100644 --- a/control_unix.go +++ b/control_unix.go @@ -10,7 +10,7 @@ import ( ) // Control defines the function to use as dialer Control to reuse the same port/address -func Control(network, address string, c syscall.RawConn) error { +func Control(_, _ string, c syscall.RawConn) error { var errSetOpts error err := c.Control(func(fd uintptr) { diff --git a/driver_test.go b/driver_test.go index 42023956..ddcbed30 100644 --- a/driver_test.go +++ b/driver_test.go @@ -60,6 +60,7 @@ func NewTestServerWithDriver(t *testing.T, driver *TestServerDriver) *FtpServer if err := os.MkdirAll(dir, 0750); err != nil { panic(err) } + driver.fs = afero.NewBasePathFs(afero.NewOsFs(), dir) } @@ -342,12 +343,12 @@ func (driver *TestServerDriver) GetTLSConfig() (*tls.Config, error) { return nil, errNoTLS } -func (driver *TestServerDriver) PreAuthUser(cc ClientContext, user string) error { +func (driver *TestServerDriver) PreAuthUser(cc ClientContext, _ string) error { return cc.SetTLSRequirement(driver.TLSRequirement) } -func (driver *TestServerDriver) VerifyConnection(cc ClientContext, user string, - tlsConn *tls.Conn) (ClientDriver, error) { +func (driver *TestServerDriver) VerifyConnection(_ ClientContext, _ string, + _ *tls.Conn) (ClientDriver, error) { switch driver.TLSVerificationReply { case tlsVerificationFailed: return nil, errInvalidTLSCertificate diff --git a/handle_auth.go b/handle_auth.go index ef5831e6..bcb4d3d5 100644 --- a/handle_auth.go +++ b/handle_auth.go @@ -76,7 +76,7 @@ func (c *clientHandler) handlePASS(param string) error { c.writeMessage(StatusNotLoggedIn, msg) c.disconnect() - case err == nil: + default: // err == nil && c.driver != nil if msg == "" { msg = "Password ok, continue" } diff --git a/handle_dirs.go b/handle_dirs.go index 361e0ef0..a832f457 100644 --- a/handle_dirs.go +++ b/handle_dirs.go @@ -140,7 +140,7 @@ func (c *clientHandler) handleRMDIR(params string) { } } -func (c *clientHandler) handleCDUP(param string) error { +func (c *clientHandler) handleCDUP(_ string) error { parent, _ := path.Split(c.Path()) if parent != "/" && strings.HasSuffix(parent, "/") { parent = parent[0 : len(parent)-1] @@ -156,7 +156,7 @@ func (c *clientHandler) handleCDUP(param string) error { return nil } -func (c *clientHandler) handlePWD(param string) error { +func (c *clientHandler) handlePWD(_ string) error { c.writeMessage(StatusPathCreated, fmt.Sprintf(`"%s" is the current directory`, quoteDoubling(c.Path()))) return nil diff --git a/handle_files.go b/handle_files.go index 870f984d..c371d592 100644 --- a/handle_files.go +++ b/handle_files.go @@ -154,6 +154,7 @@ func (c *clientHandler) doFileTransfer(tr net.Conn, file io.ReadWriter, write bo "Stream copy finished", "writtenBytes", written, ) + if written == 0 { _, err = out.Write([]byte{}) } @@ -293,6 +294,7 @@ func (c *clientHandler) handleCHOWN(params string) { { usergroup := strings.Split(spl[0], ":") userName := usergroup[0] + if id, err := strconv.ParseInt(userName, 10, 32); err == nil { userID = int(id) } else { @@ -432,6 +434,7 @@ func (c *clientHandler) handleSTATFile(param string) error { return nil } + files, errList = directory.Readdir(-1) c.closeDirectory(directoryPath, directory) } diff --git a/handle_misc.go b/handle_misc.go index db4bbf94..ffb8ae6e 100644 --- a/handle_misc.go +++ b/handle_misc.go @@ -33,13 +33,13 @@ func (c *clientHandler) handlePROT(param string) error { return nil } -func (c *clientHandler) handlePBSZ(param string) error { +func (c *clientHandler) handlePBSZ(_ string) error { c.writeMessage(StatusOK, "Whatever") return nil } -func (c *clientHandler) handleSYST(param string) error { +func (c *clientHandler) handleSYST(_ string) error { if c.server.settings.DisableSYST { c.writeMessage(StatusCommandNotImplemented, "SYST is disabled") @@ -177,7 +177,7 @@ func (c *clientHandler) handleOPTS(param string) error { return nil } -func (c *clientHandler) handleNOOP(param string) error { +func (c *clientHandler) handleNOOP(_ string) error { c.writeMessage(StatusOK, "OK") return nil @@ -190,7 +190,7 @@ func (c *clientHandler) handleCLNT(param string) error { return nil } -func (c *clientHandler) handleFEAT(param string) error { +func (c *clientHandler) handleFEAT(_ string) error { c.writeLine(fmt.Sprintf("%d- These are my features", StatusSystemStatus)) defer c.writeMessage(StatusSystemStatus, "end") @@ -272,7 +272,7 @@ func (c *clientHandler) handleTYPE(param string) error { return nil } -func (c *clientHandler) handleQUIT(param string) error { +func (c *clientHandler) handleQUIT(_ string) error { c.transferWg.Wait() var msg string diff --git a/server.go b/server.go index 3897041d..7180ab96 100644 --- a/server.go +++ b/server.go @@ -174,6 +174,7 @@ func (server *FtpServer) Listen() error { return err } + if server.settings.TLSRequired == ImplicitEncryption { // implicit TLS var tlsConfig *tls.Config @@ -184,6 +185,7 @@ func (server *FtpServer) Listen() error { return err } + server.listener = tls.NewListener(server.listener, tlsConfig) } } diff --git a/transfer_pasv.go b/transfer_pasv.go index a7e58521..76253103 100644 --- a/transfer_pasv.go +++ b/transfer_pasv.go @@ -116,7 +116,7 @@ func (c *clientHandler) findListenerWithinPortRange(portRange *PortRange) (*net. return nil, ErrNoAvailableListeningPort } -func (c *clientHandler) handlePASV(param string) error { +func (c *clientHandler) handlePASV(_ string) error { command := c.GetLastCommand() addr, _ := net.ResolveTCPAddr("tcp", ":0") var tcpListener *net.TCPListener diff --git a/transfer_test.go b/transfer_test.go index e6103203..f556361b 100644 --- a/transfer_test.go +++ b/transfer_test.go @@ -91,6 +91,7 @@ func ftpUpload(t *testing.T, ftp *goftp.Client, file io.ReadSeeker, filename str if strings.HasSuffix(stats.Name(), filename) { found = true } + if !found { t.Fatal("STAT: Couldn't find file !") } @@ -959,7 +960,7 @@ func TestPASVPublicIPResolver(t *testing.T) { require.NoError(t, err, "Couldn't open raw connection") s.settings.PublicHost = "" - s.settings.PublicIPResolver = func(cc ClientContext) (string, error) { + s.settings.PublicIPResolver = func(_ ClientContext) (string, error) { return "127.0.0", nil } // we crash if the PublicIPResolver returns an invalid IP, this must be fixed outside the lib @@ -968,7 +969,7 @@ func TestPASVPublicIPResolver(t *testing.T) { require.Equal(t, StatusServiceNotAvailable, rc) require.Contains(t, resp, "invalid passive IP") - s.settings.PublicIPResolver = func(cc ClientContext) (string, error) { + s.settings.PublicIPResolver = func(_ ClientContext) (string, error) { return "", errConnectionNotAllowed }