Home > Software design >  Cannot connect to FTP server using Go but can connect using FileZilla
Cannot connect to FTP server using Go but can connect using FileZilla

Time:01-21

I have a small Golang program and I'm trying to connect to an FTP server running in a docker container (https://registry.hub.docker.com/r/atmoz/sftp).

My machine is a M1 Pro MacBook.

The container is started with the following command: docker run -p 22:22 -d atmoz/sftp foo:pass:::upload

The Go version is 1.17.13.

The code code of the program is the following:

package main

import (
    "log"
    "time"

    "github.com/jlaffaye/ftp"
)

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

    err = c.Login("foo", "pass")
    if err != nil {
        log.Fatal(err, "cannot login")
    }

    // Do something with the FTP conn

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

Somehow, I'm unable to connect to the FTP server executing this code, it results in the following output:

EOF cannot connect

I tried connect to the same FTP server using FileZilla and it works fine, im able to connect to the server with success.

Any ideias on how to fix this or further debug the issue? Thank you

CodePudding user response:

The port 22 is typically SSH/SFTP, not FTP. Note that FileZilla supports both FTP and SFTP. So chances are that you are actually connecting with SFTP using FileZilla. Those two protocols are completely different and incompatible.

There seems to be an "sftp" package for Go:
https://pkg.go.dev/github.com/pkg/sftp

  • Related