1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-24 16:54:00 +00:00

sftp: implement open with config

This commit is contained in:
Alexander Neumann 2015-12-28 18:22:19 +01:00
parent 7b1e8fdd06
commit f7c9091970

View file

@ -92,6 +92,23 @@ func Open(dir string, program string, args ...string) (*SFTP, error) {
return sftp, nil return sftp, nil
} }
func buildSSHCommand(cfg Config) []string {
args := []string{cfg.Host}
if cfg.User != "" {
args = append(args, "-l")
args = append(args, cfg.User)
}
args = append(args, "-s")
args = append(args, "sftp")
return args
}
// OpenWithConfig opens an sftp backend as described by the config by running
// "ssh" with the appropiate arguments.
func OpenWithConfig(cfg Config) (*SFTP, error) {
return Open(cfg.Dir, "ssh", buildSSHCommand(cfg)...)
}
// Create creates all the necessary files and directories for a new sftp // Create creates all the necessary files and directories for a new sftp
// backend at dir. Afterwards a new config blob should be created. // backend at dir. Afterwards a new config blob should be created.
func Create(dir string, program string, args ...string) (*SFTP, error) { func Create(dir string, program string, args ...string) (*SFTP, error) {
@ -138,6 +155,12 @@ func Create(dir string, program string, args ...string) (*SFTP, error) {
return Open(dir, program, args...) return Open(dir, program, args...)
} }
// CreateWithConfig creates an sftp backend as described by the config by running
// "ssh" with the appropiate arguments.
func CreateWithConfig(cfg Config) (*SFTP, error) {
return Create(cfg.Dir, "ssh", buildSSHCommand(cfg)...)
}
// Location returns this backend's location (the directory name). // Location returns this backend's location (the directory name).
func (r *SFTP) Location() string { func (r *SFTP) Location() string {
return r.p return r.p