Skip to content

client.MkdirAll not returning an error when docs state it should #609

@ctfrancia

Description

@ctfrancia

Hi, I am just making a project learning about sftp and transferring data, anyways, I am making a directory, creating a file within it, and then extending that file directory by one. According to the docs of MkdirAll it says:

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. If path is already a directory, MkdirAll does nothing and returns nil. If path contains a regular file, an error is returned

however nil is still received back in the code below

	// connect to ssh server
	conn, err := ssh.Dial("tcp", sshAddr, config)
	if err != nil {
		log.Fatal("Failed to dial: ", err)
	}

	defer conn.Close()

	// open an SFTP session over an existing ssh connection.
	client, err := sftp.NewClient(conn)
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	var user = "USER"
	var sftpBasePath = fmt.Sprintf("home/%s", user)
	err = client.MkdirAll(sftpBasePath)
	if err != nil {
		log.Fatal(err)
	}

	// leave your mark
	f, err := client.Create(fmt.Sprintf("%s/hello.txt", sftpBasePath))
	if err != nil {
		log.Fatal(err)
	}

	if _, err := f.Write([]byte("Hello world!")); err != nil {
		log.Fatal(err)
	}

	// error should be returned below as there is a ".txt"
        // file in the path before creating the `dir` directory
	err = client.MkdirAll(sftpBasePath + "/dir")
	if err != nil {
		log.Fatal(err)
	}

	f.Close()

I should also mention that the ssh server when I inspect the documents the file is created at that path and the dir directory

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