title: Go SMB2 , reading and listing directory
body: <p>I'm trying to list directory contents on a share from Linux to Windows using Go.
  So far I've managed to Create/Remove new files inside a share with full Read/Write permissions.</p>
  
  <p>Go module: <a href="https://godoc.org/github.com/hirochachacha/go-smb2#Client" rel="nofollow noreferrer">https://godoc.org/github.com/hirochachacha/go-smb2#Client</a></p>
  
  <p>Functions:</p>
  
  <pre><code>func connect_client(host string, share string, session map[string]string) *smb2.Client {
      //Checks for a connection on port
      conn, err := net.Dial("tcp", host+":445")
      if err != nil {
          panic(err)
      }
      //smb auth
      d := &amp;smb2.Dialer{
          Initiator: &amp;smb2.NTLMInitiator{
              User:     session["Username"],
              Password: session["Password"],
              Domain:   session["Domain"],
          },
      }
      //Returns a client session
      client, err := d.Dial(conn)
      if err != nil {
          fmt.Println("Connection failed")
          client.Logoff()
      } else {
          fmt.Println("Connection Succeeded")
      }
      return client
  }
  
  func check_write(host string, client *smb2.Client) {
      file := "asdasdas.txt"
      fs, err := client.Mount(host)
      if err != nil {
          fmt.Println(err)
          os.Exit(0)
      }
      defer fs.Umount()
      share := strings.Split(host, `\\`)
      f, err := fs.Create(file)
      if err != nil {
          fmt.Println("You do not have write permissions on directory:%s ! \n", strings.Split(share[1], `\`)[1])
          os.Exit(0)
  
      }
      defer fs.Remove(file)
      defer f.Close()
      fmt.Printf("You have write permissions to directory: %s \n", strings.Split(share[1], `\`)[1]))
  
  }
  
  func list_all(client *smb2.Client, host string) {
      fs, err := client.Mount(host)
      if err != nil {
          fmt.Println(err)
          os.Exit(0)
      }
      defer fs.Umount()
  
      _, err = fs.Open(`Test.txt`)
      if err != nil {
          fmt.Println(err)
          os.Exit(0)
      }
  
  }
  
  func main() {
      host, share, action, session := get_flags()
      client := connect_client(host, share, session)
      full_host := `\\` + host + `\` + share
  
      //File create
      if action == "check_write" {
          check_write(full_host, client)
      }
      if action == "list_files" {
          list_all(client, full_host)
      }
  
  }
  </code></pre>
  
  <p>In the function list_all() everything works, but when I am trying to access \\192.168.1.19\Sharing only..
  When I input just a host with directory name it seas it can not list the directory path because it can not find the object specified.
  I can't understand how I can get pointer used for *RemoteFile in order to use the functions:</p>
  
  <p>f.Readdir()</p>
  
  <p>f.Name() 
  etc....</p>
  
  <p>So far I managed to use *RemoteFileSystem only for all other actions but I want to list all contents of the directory..</p>
  
  <p>Help would be much appreciated!</p>
  
  <p>Edit:
  If it wasn't clear enough, in order to use functions like:
  f.Readdir() 
  f.Name()
  I need to get a pointer for *RemoteFile, this is my main issue</p>