Пример #1
0
func readSFTPTree(sftpClient *sftp.Client, p *SSHPath, dest *[]Path) error {
	files, err := sftpClient.ReadDir(p.path)
	if err != nil {
		return err
	}
	for _, f := range files {
		child := NewSSHPath(p.client, p.server, path.Join(p.path, f.Name()), p.sudo)

		*dest = append(*dest, child)

		if f.IsDir() {
			err = readSFTPTree(sftpClient, child, dest)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Пример #2
-1
func (conn *SshConfig) GlobHandler(rPath string, sftp *sftp.Client, env *Enviroment) error {
	rPaths := make([]string, 0)

	files, err := sftp.ReadDir(PathCutFile(rPath))
	if err != nil {
		return err
	}

	for _, file := range files {
		if glob.Glob(PathChomp(rPath), file.Name()) {

			if IsRegularFile(file) {
				rPaths = append(rPaths, JoinPath(rPath, file.Name()))
			}
		}
	}

	if len(rPaths) > 0 {
		if _, err := os.Stat(conn.Name); os.IsNotExist(err) {
			os.Mkdir(conn.Name, 0755)
		}

		for _, rp := range rPaths {
			conn.GetFile(rp, filepath.Join(conn.Name, PathChomp(rp)), sftp, env)
		}
	}

	return nil
}