ftp icon indicating copy to clipboard operation
ftp copied to clipboard

connection to bad ftp server hangs whole connection most of the time

Open boindil opened this issue 3 years ago • 5 comments

Describe the bug The connection attempts to not abort properly

To Reproduce I've set up an ftp server that can be reached somewhat, but is not fully functional (as tested via telnet)

package main

import (
	"log"
	"time"

	"github.com/jlaffaye/ftp"
)

func main() {
	c, err := ftp.Dial("10.0.2.2:21", ftp.DialWithTimeout(5*time.Second))
	if err != nil {
		log.Fatal(err)
	}

	err = c.Login("anonymous", "anonymous")
	if err != nil {
		log.Fatal(err)
	}

	// Do something with the FTP conn

	if err := c.Quit(); err != nil {
		log.Fatal(err)
	}
}

Expected behavior dialing is aborted after timeout p.s.: adding DialWithContext and adding a context that is cancelled after x seconds does not work either

FTP server

  • Name and version: Windows 10 1909 integrated FTP via IIS services
  • Public URL if applicable

Debug output DialWithDebugOutput literally does nothing when it comes to the error. I guess that somethings waiting for more data to be submitted by the FTP server, but that never happens - thus its hanging.

Additional context Go: go version go1.18.1 linux/amd64

sometime EOF error, sometimes not image

corresponds to telnet tests, but this is still not a working FTP connection (command line FTP clients do not work either) note the ^C in the lower left. The connection would stay open until I did something, while the first one aborts immediately (i guess thats the EOF case) image

boindil avatar Apr 27 '22 09:04 boindil

Oh, yes, the timeout is for opening the TCP connection. It is not currently used for every read/write.

jlaffaye avatar May 04 '22 15:05 jlaffaye

In my case it was an attempt to connect to freeSSHd: http://www.freesshd.com/ (identifies as SSH-2.0-WeOnlyDo 2.4.3)

In the Dial we expect to get a status code, but the freeSSHd replies with a single line SSH-2.0-WeOnlyDo 2.4.3, then the next ReadLine() hungs.

@jlaffaye does it make sense to set SetReadDeadline on the underlying network connection in the Dial ?

glebteterin avatar Feb 26 '23 21:02 glebteterin

I had the same problem

lanyi1998 avatar May 27 '23 16:05 lanyi1998