Commit 7b477e8b authored by Bruce Flynn's avatar Bruce Flynn
Browse files

tweak help a bit; use env vars HOME and USER

parent 0356198c
......@@ -8,7 +8,6 @@ import (
"io/ioutil"
url_ "net/url"
"os"
"os/user"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
......@@ -263,11 +262,7 @@ func cleanURL(url string) (url_.URL, error) {
username := u.User.Username()
if len(username) == 0 {
cu, err := user.Current()
if err != nil {
panic(errors.Wrapf(err, "can't get current user"))
}
username = cu.Username
username = os.Getenv("USER")
}
newURL.User = url_.User(username)
......
......@@ -26,11 +26,7 @@ func debug(fmt string, args ...interface{}) {
}
func defaultPrivateKey() string {
homeDir, err := os.UserHomeDir()
if err != nil {
panic("could not determine user home dir")
}
return path.Join(homeDir, ".ssh/id_rsa")
return path.Join(os.Getenv("HOME"), ".ssh/id_rsa")
}
func main() {
......@@ -40,28 +36,17 @@ func main() {
pflag.Usage = func() {
fmt.Fprintf(os.Stderr, `%s [options]
A mini JSON API for performing SFTP commands.
Supported commands read from commands:
{"command": "PUT", "args": {"source": <path>, "dest": <path>}}
{"command": "GET", "args": {"source": <path>, "dest": <path>}}
{"command": "LISTDIR", "args": {"path": <path>}}
returns [{"name": "<filename>", "size": <bytes>, "mtime": <unixtime>}, ...]
{"command": "DELETE", "args": {"path": <path>}}
Responses written to stdout:
{"status": "(ok|error|fail)", "message": "<err message>", "data": (""|??)}
where "data" is documented with the command.
Mini in-process API to drive an SFTP connection.
Options:
`, os.Args[0])
pflag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\n%s\n", buildStr)
fmt.Fprintf(os.Stderr, `
%s
https://gitlab.ssec.wisc.edu/brucef/sftper
`, buildStr)
}
var (
......@@ -74,7 +59,7 @@ Options:
pKey = pflag.StringP("pkey", "i", defaultPrivateKey(), "Path to PEM formatted private key.")
hKey = pflag.StringP("hkey", "h", "", "Path to PEM formatted host public key. If not "+
"provided server host key checking will be disabled. To get a server host key run "+
"ssh-keyscan -t rsa <hostname>.")
"'ssh-keyscan -t rsa <hostname>'.")
)
pflag.BoolVar(&verbose, "verbose", false, "Verbose output to stderr")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment