Skip to content

sftp.NewClient returns "EOF" error #506

Closed

Description

@mraxrorxon

I create sshClient like this:
if sshClient, err = ssh.Dial("tcp", addr, clientConfig); err != nil {
return nil, err
}; and sshClient is created successfully, after that create sftp client like this:

if sftpClient, err = sftp.NewClient(sshClient); err != nil {
return nil, err
} here I get an error "EOF"
Please help this, where is a problam?

Activity

  1. changed the title [-]sftp.NewClient returns "EOF" erro[/-] [+]sftp.NewClient returns "EOF" error[/+] on May 16, 2022
  2. puellanivis commented on May 16, 2022

    @puellanivis
    Collaborator

    Could you maybe share the whole of your function(s)? And encase it in a triple-backtick code block? There is not really enough information here to diagnose what might be going on.

  3. npsables commented on Jun 29, 2022

    @npsables

    My problem was the section Subsystem in /etc/ssh/sshd_config of the target server was wrong or missing. Fixed by correcting this section then restart the service.

    But to be honest, the error io.EOF returned is very confusing, maybe we should add diagnosis here?

    func (c *Client) recvVersion() error {
    	typ, data, err := c.recvPacket(0)
    	if err == io.EOF {
    		// do some diagnose here
    		err = nil
    	}
           ...
    }
    
  4. puellanivis commented on Jun 29, 2022

    @puellanivis
    Collaborator

    Hm… yeah, we could probably do something there, but there’s not much to diagnose at that point. If we get an EOF there, then we’re stuck in an unrecoverable state. However, we could use fmt.Errorf("problem receiving version packet: %w", err) or maybe even convert it to io.ErrUnexpectedEOF as well.

  5. npsables commented on Jun 29, 2022

    @npsables

    Yea, and maybe we should add some comments if someone has the same problem. Hope this help someone.

  6. christhomas commented on Oct 15, 2026

    @christhomas
    Contributor

    We did a small code audit of the open issues, and we think this one is already addressed.

    #513 (released in v1.13.6) added the context suggested above. If the server closes the connection before sending its version packet, NewClient no longer returns a bare EOF. Instead it returns:

    error receiving version packet from server: server unexpectedly closed connection: unexpected EOF
    

    and the error wraps io.ErrUnexpectedEOF:

    sftp/client.go

    Lines 320 to 328 in 16147c5

    func (c *Client) recvVersion() error {
    typ, data, err := c.recvPacket(0)
    if err != nil {
    if err == io.EOF {
    return fmt.Errorf("server unexpectedly closed connection: %w", io.ErrUnexpectedEOF)
    }
    return err
    }

    We checked this against current master with a server that closes the connection immediately. So we think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions