func SCPSendDir(path string, fi os.FileInfo, src *bufio.Reader, dst io.Writer) error {
	if fi == nil {
		if statfi, err := os.Stat(path); err != nil {
			return err
		} else {
			fi = statfi
		}
	}
	dbg.Debug("Preparing to send dir: %s", path)
	cmd := buildSCPCommand(fi)
	if _, err := dst.Write([]byte(cmd)); err != nil {
		return err
	}
	dbg.Debug("sent header")
	if err := readAck(src); err != nil {
		return err
	}
	if contents, err := ioutil.ReadDir(path); err != nil {
		scpSendAck(dst, SCPFatal, err.Error())
		return err
	} else {
		for _, child := range contents {
			lpath := filepath.Join(path, child.Name())
			if child.IsDir() {
				SCPSendDir(lpath, child, src, dst)
			} else {
				SCPSendFile2(lpath, child, src, dst)
			}
		}
	}
	if _, err := dst.Write([]byte("E\n")); err != nil {
		return err
	}
	if err := readAck(src); err != nil {
		return err
	}
	dbg.Debug("Done sending dir: %s", path)
	return nil
}
Send a directory
package main
import (
	"bufio"
	"errors"
	"fmt"
	"golang.org/x/crypto/ssh"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"strconv"
	"strings"
)
const (
	SCPCopy = iota
	SCPDir
	SCPEndDir
	SCPTime
)
const (
	SCPOK = iota
	SCPError
	SCPFatal
)
type SCPCommand struct {
	CommandType int
	Mode        int16
	Length      int64
	Name        string
}
var (
	SCP_END_COMMANDS  = "\x00"
	ErrInvalidAck     = errors.New("Invalid ack code.")
	ErrInvalidPieces  = errors.New("Invalid number of command pieces.")
	ErrNotRegularFile = errors.New("Not a regular file.")
	ErrNotDirectory   = errors.New("Not a directory.")
)
func (conn *ServerConn) SCPHandler(shellCmd []string, ch ssh.Channel) error {
	shellCmd = shellCmd[1:]  
	var path string
	var source bool
	var dirMode bool
	var recursive bool
	for _, opt := range shellCmd {
		switch opt {
		case "-t":
			source = false
		case "-f":
			source = true
		case "-d":
			dirMode = true
		case "-r":
			recursive = true
		case "-p":
		case "-v":
		default:
			dbg.Debug("scp path: %s", opt)
			path = opt
		}
	}
	var err error
	if source {
		err = conn.SCPSource(path, dirMode, recursive, ch)
	} else {
		err = conn.SCPSink(path, dirMode, ch)
	}
	if err != nil {
		scpSendError(ch, err)
	}
	ch.CloseWrite()
	return err
}
func (conn *ServerConn) SCPSource(path string, dirMode bool, recursive bool, ch ssh.Channel) error {
	src := bufio.NewReader(ch)
	if err := readAck(src); err != nil {
		return err
	}
	if recursive {
		return SCPSendDir(path, nil, src, ch)
	}
	return SCPSendFile(path, src, ch)
}