mirror of https://gogs.blitter.com/RLabs/xs
client->server and server->client file/dir copies minimally working
This commit is contained in:
parent
7867f84b87
commit
ca2b6efd9b
|
@ -105,7 +105,7 @@ func parseNonSwitchArgs(a []string, dp string) (user, host, port, path string, i
|
||||||
func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, recurs bool, rec *cmdSpec) (err error, exitStatus int) {
|
func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, recurs bool, rec *cmdSpec) (err error, exitStatus int) {
|
||||||
if remoteDest {
|
if remoteDest {
|
||||||
fmt.Println("local files:", files, "remote filepath:", string(rec.cmd))
|
fmt.Println("local files:", files, "remote filepath:", string(rec.cmd))
|
||||||
fmt.Fprintf(conn, "copyMode remoteDest ...\n")
|
//fmt.Fprintf(conn, "copyMode remoteDest ...\n")
|
||||||
|
|
||||||
var c *exec.Cmd
|
var c *exec.Cmd
|
||||||
|
|
||||||
|
@ -114,14 +114,17 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, recurs bool,
|
||||||
//os.Setenv("TERM", "vt102") // TODO: server or client option?
|
//os.Setenv("TERM", "vt102") // TODO: server or client option?
|
||||||
|
|
||||||
cmdName := "/bin/tar"
|
cmdName := "/bin/tar"
|
||||||
cmdArgs := []string{"-cz", "-f", "/dev/stdout", files}
|
cmdArgs := []string{"-c", "-f", "/dev/stdout", strings.TrimSpace(files)}
|
||||||
fmt.Printf("[%v %v]\n", cmdName, cmdArgs)
|
fmt.Printf("[%v %v]\n", cmdName, cmdArgs)
|
||||||
// NOTE the lack of quotes around --xform option's sed expression.
|
// NOTE the lack of quotes around --xform option's sed expression.
|
||||||
// When args are passed in exec() format, no quoting is required
|
// When args are passed in exec() format, no quoting is required
|
||||||
// (as this isn't input from a shell) (right? -rlm 20180823)
|
// (as this isn't input from a shell) (right? -rlm 20180823)
|
||||||
//cmdArgs := []string{"-xvz", "-C", files, `--xform=s#.*/\(.*\)#\1#`}
|
//cmdArgs := []string{"-xvz", "-C", files, `--xform=s#.*/\(.*\)#\1#`}
|
||||||
c = exec.Command(cmdName, cmdArgs...)
|
c = exec.Command(cmdName, cmdArgs...)
|
||||||
|
c.Dir, _ = os.Getwd()
|
||||||
|
fmt.Println("[wd:", c.Dir, "]")
|
||||||
c.Stdout = conn
|
c.Stdout = conn
|
||||||
|
c.Stderr = os.Stderr
|
||||||
|
|
||||||
// Start the command (no pty)
|
// Start the command (no pty)
|
||||||
err = c.Start() // returns immediately
|
err = c.Start() // returns immediately
|
||||||
|
@ -147,7 +150,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, recurs bool,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("remote filepath:", string(rec.cmd), "local files:", files)
|
fmt.Println("remote filepath:", string(rec.cmd), "local files:", files)
|
||||||
fmt.Fprintf(conn, "copyMode localDest ...\n")
|
//fmt.Fprintf(conn, "copyMode localDest ...\n")
|
||||||
var c *exec.Cmd
|
var c *exec.Cmd
|
||||||
|
|
||||||
//os.Clearenv()
|
//os.Clearenv()
|
||||||
|
@ -162,7 +165,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, recurs bool,
|
||||||
// destPath := strings.Join({os.Getenv("PWD"),files}, os.PathSeparator)
|
// destPath := strings.Join({os.Getenv("PWD"),files}, os.PathSeparator)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
cmdArgs := []string{"-xvz", "-C", destPath}
|
cmdArgs := []string{"-x", "-C", destPath}
|
||||||
fmt.Printf("[%v %v]\n", cmdName, cmdArgs)
|
fmt.Printf("[%v %v]\n", cmdName, cmdArgs)
|
||||||
// NOTE the lack of quotes around --xform option's sed expression.
|
// NOTE the lack of quotes around --xform option's sed expression.
|
||||||
// When args are passed in exec() format, no quoting is required
|
// When args are passed in exec() format, no quoting is required
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -38,7 +39,7 @@ type cmdSpec struct {
|
||||||
|
|
||||||
/* -------------------------------------------------------------- */
|
/* -------------------------------------------------------------- */
|
||||||
// Perform a client->server copy
|
// Perform a client->server copy
|
||||||
func runClientToServerCopyAs(who string, conn hkexnet.Conn, destPath string, chaffing bool) (err error, exitStatus int) {
|
func runClientToServerCopyAs(who string, conn hkexnet.Conn, fpath string, chaffing bool) (err error, exitStatus int) {
|
||||||
u, _ := user.Lookup(who)
|
u, _ := user.Lookup(who)
|
||||||
var uid, gid uint32
|
var uid, gid uint32
|
||||||
fmt.Sscanf(u.Uid, "%d", &uid)
|
fmt.Sscanf(u.Uid, "%d", &uid)
|
||||||
|
@ -58,22 +59,42 @@ func runClientToServerCopyAs(who string, conn hkexnet.Conn, destPath string, cha
|
||||||
|
|
||||||
var c *exec.Cmd
|
var c *exec.Cmd
|
||||||
cmdName := "/bin/tar"
|
cmdName := "/bin/tar"
|
||||||
|
|
||||||
|
var destDir string
|
||||||
|
if path.IsAbs(fpath) {
|
||||||
|
destDir = fpath
|
||||||
|
} else {
|
||||||
|
destDir = path.Join(u.HomeDir, fpath)
|
||||||
|
}
|
||||||
|
//stat, pe := os.Stat(destDir)
|
||||||
|
//_ = stat
|
||||||
|
//if pe != nil {
|
||||||
|
// log.Fatal(pe)
|
||||||
|
// return pe, 252 // ?!
|
||||||
|
//}
|
||||||
|
|
||||||
|
//if stat.IsDir(destBase) {
|
||||||
|
cmdArgs := []string{"-x", "-C", destDir}
|
||||||
|
//} else {
|
||||||
|
// cmdArgs := []string{"-x",
|
||||||
|
|
||||||
// NOTE the lack of quotes around --xform option's sed expression.
|
// NOTE the lack of quotes around --xform option's sed expression.
|
||||||
// When args are passed in exec() format, no quoting is required
|
// When args are passed in exec() format, no quoting is required
|
||||||
// (as this isn't input from a shell) (right? -rlm 20180823)
|
// (as this isn't input from a shell) (right? -rlm 20180823)
|
||||||
cmdArgs := []string{"-xvz", "-C", destPath}
|
|
||||||
//cmdArgs := []string{"-xvz", "-C", destPath, `--xform=s#.*/\(.*\)#\1#`}
|
//cmdArgs := []string{"-xvz", "-C", destPath, `--xform=s#.*/\(.*\)#\1#`}
|
||||||
c = exec.Command(cmdName, cmdArgs...)
|
c = exec.Command(cmdName, cmdArgs...)
|
||||||
|
|
||||||
|
c.Dir = destDir
|
||||||
|
|
||||||
//If os.Clearenv() isn't called by server above these will be seen in the
|
//If os.Clearenv() isn't called by server above these will be seen in the
|
||||||
//client's session env.
|
//client's session env.
|
||||||
//c.Env = []string{"HOME=" + u.HomeDir, "SUDO_GID=", "SUDO_UID=", "SUDO_USER=", "SUDO_COMMAND=", "MAIL=", "LOGNAME="+who}
|
//c.Env = []string{"HOME=" + u.HomeDir, "SUDO_GID=", "SUDO_UID=", "SUDO_USER=", "SUDO_COMMAND=", "MAIL=", "LOGNAME="+who}
|
||||||
c.Dir = u.HomeDir
|
//c.Dir = u.HomeDir
|
||||||
c.SysProcAttr = &syscall.SysProcAttr{}
|
c.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
c.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}
|
c.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}
|
||||||
c.Stdin = conn
|
c.Stdin = conn
|
||||||
//c.Stdout = conn
|
c.Stdout = os.Stdout
|
||||||
//c.Stderr = conn
|
c.Stderr = os.Stderr
|
||||||
|
|
||||||
if chaffing {
|
if chaffing {
|
||||||
conn.EnableChaff()
|
conn.EnableChaff()
|
||||||
|
@ -129,7 +150,7 @@ func runServerToClientCopyAs(who string, conn hkexnet.Conn, srcPath string, chaf
|
||||||
|
|
||||||
var c *exec.Cmd
|
var c *exec.Cmd
|
||||||
cmdName := "/bin/tar"
|
cmdName := "/bin/tar"
|
||||||
cmdArgs := []string{"-cz", "-f", "-", srcPath}
|
cmdArgs := []string{"-c", "-f", "-", srcPath}
|
||||||
c = exec.Command(cmdName, cmdArgs...)
|
c = exec.Command(cmdName, cmdArgs...)
|
||||||
|
|
||||||
//If os.Clearenv() isn't called by server above these will be seen in the
|
//If os.Clearenv() isn't called by server above these will be seen in the
|
||||||
|
|
Loading…
Reference in New Issue