code: func (cmd *command) serveSink(ch io.ReadWriter) error {
  	// Validate that if directory mode flag was sent, the target is an actual
  	// directory.
  	if cmd.Flags.DirectoryMode {
  		if len(cmd.Flags.Target) != 1 {
  			return trace.BadParameter("in directory mode, only single upload target is allowed, %v provided", len(cmd.Flags.Target))
  		}
  
  		fi, err := os.Stat(cmd.Flags.Target[0])
  		if err != nil {
  			return trace.Wrap(err)
  		}
  		if mode := fi.Mode(); !mode.IsDir() {
  			return trace.BadParameter("target path must be a directory")
  		}
  	}
  
  	if err := sendOK(ch); err != nil {
  		return trace.Wrap(err)
  	}
  	var st state
  	st.path = []string{"."}
  	var b = make([]byte, 1)
  	scanner := bufio.NewScanner(ch)
  	for {
  		n, err := ch.Read(b)
  		if err != nil {
  			if err == io.EOF {
  				return nil
  			}
  			return trace.Wrap(err)
  		}
  
  		if n < 1 {
  			return trace.Errorf("unexpected error, read 0 bytes")
  		}
  
  		if b[0] == OKByte {
  			continue
  		}
  
  		scanner.Scan()
  		if err := scanner.Err(); err != nil {
  			return trace.Wrap(err)
  		}
  		if err := cmd.processCommand(ch, &st, b[0], scanner.Text()); err != nil {
  			return trace.Wrap(err)
  		}
  		if err := sendOK(ch); err != nil {
  			return trace.Wrap(err)
  		}
  	}
  }
docs: // serveSink executes file uploading, when a remote server sends file(s)
  // via scp