go-smb2 icon indicating copy to clipboard operation
go-smb2 copied to clipboard

Failure when creating a file in a folder that has whitespaces in the name

Open Sparkz0629 opened this issue 2 years ago • 2 comments

When attempting to create a file in a folder that has spaces in the name, we get the following error:

open FOLDER WITH SPACES\sambaTest.test: file does not exist

Our code looks as follows:

       conn, err := net.Dial("tcp", "testServer.com:445")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to connecto to [%s]: %v\n", addr, err)
		return err
	}
	defer conn.Close()

	d := &smb2.Dialer{
		Initiator: &smb2.NTLMInitiator{
			User:     user,
			Password: pass,
			Domain:   <Domain Name>,
		},
	}

	s, err := d.Dial(conn)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable connect to server: %v\n", err)
		return err
	}
	defer s.Logoff()

	fs, err := s.Mount("SHARE")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to mount share: %v\n", err)
		return err
	}
	defer fs.Umount()

	destFile := "FOLDER WITH SPACES/sambaTest.test"

        // The code fails on the below lin
        f, err := fs.Create(destFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to create file: %v\n", err)
		return err
	}
	defer f.Close()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to write to file: %v\n", err)
		return err
	}
	fmt.Fprintf(os.Stdout, "%d bytes copied\n", bytes)

Has anyone seen similar issues?

Sparkz0629 avatar Mar 03 '22 18:03 Sparkz0629

This appears to be a permissions error.

Using smbClient (version 4.6.5) on solaris i can see contents in the SHARE drive that gets mounts. However, using go-smb2 or my macbook, the SHARE folder is completely empty.

Same user and password, successfully validates, just no contents... any ideas?

Sparkz0629 avatar Mar 03 '22 18:03 Sparkz0629

wireshark might be the last resort :)

hirochachacha avatar Mar 04 '22 11:03 hirochachacha