2022-03-31 03:07:33 +00:00
|
|
|
# $OpenBSD: sftp-cmds.sh,v 1.15 2022/03/31 03:07:33 djm Exp $
|
2003-01-22 06:53:16 +00:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
# XXX - TODO:
|
|
|
|
# - chmod / chown / chgrp
|
|
|
|
# - -p flag for get & put
|
|
|
|
|
|
|
|
tid="sftp commands"
|
|
|
|
|
2003-09-04 04:26:31 +00:00
|
|
|
# test that these files are readable!
|
|
|
|
for i in `(cd /bin;echo l*)`
|
|
|
|
do
|
|
|
|
if [ -r $i ]; then
|
|
|
|
GLOBFILES="$GLOBFILES $i"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2003-07-19 10:11:54 +00:00
|
|
|
# Path with embedded quote
|
|
|
|
QUOTECOPY=${COPY}".\"blah\""
|
|
|
|
QUOTECOPY_ARG=${COPY}'.\"blah\"'
|
2007-10-26 04:54:12 +00:00
|
|
|
# File with spaces
|
|
|
|
SPACECOPY="${COPY} this has spaces.txt"
|
|
|
|
SPACECOPY_ARG="${COPY}\ this\ has\ spaces.txt"
|
|
|
|
# File with glob metacharacters
|
|
|
|
GLOBMETACOPY="${COPY} [metachar].txt"
|
2003-07-19 10:11:54 +00:00
|
|
|
|
2012-06-30 05:04:13 +00:00
|
|
|
rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
|
2003-06-18 12:41:41 +00:00
|
|
|
mkdir ${COPY}.dd
|
2003-01-22 06:53:16 +00:00
|
|
|
|
|
|
|
verbose "$tid: lls"
|
2009-10-06 23:43:57 +00:00
|
|
|
(echo "lcd ${OBJ}" ; echo "lls") | ${SFTP} -D ${SFTPSERVER} 2>&1 | \
|
2008-03-14 01:21:06 +00:00
|
|
|
grep copy.dd >/dev/null 2>&1 || fail "lls failed"
|
2008-03-12 12:59:43 +00:00
|
|
|
|
|
|
|
verbose "$tid: lls w/path"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "lls ${OBJ}" | ${SFTP} -D ${SFTPSERVER} 2>&1 | \
|
2008-03-14 01:21:06 +00:00
|
|
|
grep copy.dd >/dev/null 2>&1 || fail "lls w/path failed"
|
2003-01-22 06:53:16 +00:00
|
|
|
|
|
|
|
verbose "$tid: ls"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "ls ${OBJ}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "ls failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: shell"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "!echo hi there" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "shell failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: pwd"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "pwd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "pwd failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: lpwd"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "lpwd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "lpwd failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: quit"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "quit" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "quit failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: help"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "help" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "help failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
rm -f ${COPY}
|
|
|
|
verbose "$tid: get"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "get $DATA $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "get failed"
|
|
|
|
cmp $DATA ${COPY} || fail "corrupted copy after get"
|
|
|
|
|
2003-10-08 07:52:10 +00:00
|
|
|
rm -f ${COPY}
|
|
|
|
verbose "$tid: get quoted"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "get \"$DATA\" $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-10-08 07:52:10 +00:00
|
|
|
|| fail "get failed"
|
|
|
|
cmp $DATA ${COPY} || fail "corrupted copy after get"
|
|
|
|
|
|
|
|
rm -f ${QUOTECOPY}
|
|
|
|
cp $DATA ${QUOTECOPY}
|
|
|
|
verbose "$tid: get filename with quotes"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "get failed"
|
2003-10-08 07:52:10 +00:00
|
|
|
cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes"
|
|
|
|
rm -f ${QUOTECOPY} ${COPY}
|
|
|
|
|
2007-10-26 04:54:12 +00:00
|
|
|
rm -f "$SPACECOPY" ${COPY}
|
|
|
|
cp $DATA "$SPACECOPY"
|
|
|
|
verbose "$tid: get filename with spaces"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "get ${SPACECOPY_ARG} ${COPY}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2007-10-26 04:54:12 +00:00
|
|
|
|| fail "get failed"
|
|
|
|
cmp ${COPY} "$SPACECOPY" || fail "corrupted copy after get with spaces"
|
|
|
|
|
|
|
|
rm -f "$GLOBMETACOPY" ${COPY}
|
|
|
|
cp $DATA "$GLOBMETACOPY"
|
|
|
|
verbose "$tid: get filename with glob metacharacters"
|
|
|
|
echo "get \"${GLOBMETACOPY}\" ${COPY}" | \
|
2009-10-06 23:43:57 +00:00
|
|
|
${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "get failed"
|
2007-10-26 04:54:12 +00:00
|
|
|
cmp ${COPY} "$GLOBMETACOPY" || \
|
|
|
|
fail "corrupted copy after get with glob metacharacters"
|
|
|
|
|
2003-06-18 12:41:41 +00:00
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: get to directory"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "get $DATA ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 12:41:41 +00:00
|
|
|
|| fail "get failed"
|
2013-07-25 02:11:18 +00:00
|
|
|
cmp $DATA ${COPY}.dd/$DATANAME || fail "corrupted copy after get"
|
2003-06-18 12:41:41 +00:00
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: glob get to directory"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "get /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 12:41:41 +00:00
|
|
|
|| fail "get failed"
|
|
|
|
for x in $GLOBFILES; do
|
|
|
|
cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: get to local dir"
|
2009-10-06 23:43:57 +00:00
|
|
|
(echo "lcd ${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 12:41:41 +00:00
|
|
|
|| fail "get failed"
|
2013-07-25 02:11:18 +00:00
|
|
|
cmp $DATA ${COPY}.dd/$DATANAME || fail "corrupted copy after get"
|
2003-06-18 12:41:41 +00:00
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: glob get to local dir"
|
2009-10-06 23:43:57 +00:00
|
|
|
(echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 12:41:41 +00:00
|
|
|
|| fail "get failed"
|
|
|
|
for x in $GLOBFILES; do
|
|
|
|
cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
|
|
|
|
done
|
|
|
|
|
2003-01-22 06:53:16 +00:00
|
|
|
rm -f ${COPY}
|
|
|
|
verbose "$tid: put"
|
2007-10-26 04:54:12 +00:00
|
|
|
echo "put $DATA $COPY" | \
|
2009-10-06 23:43:57 +00:00
|
|
|
${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
|
2003-01-22 06:53:16 +00:00
|
|
|
cmp $DATA ${COPY} || fail "corrupted copy after put"
|
|
|
|
|
2003-07-19 10:11:54 +00:00
|
|
|
rm -f ${QUOTECOPY}
|
|
|
|
verbose "$tid: put filename with quotes"
|
2007-10-26 04:54:12 +00:00
|
|
|
echo "put $DATA \"$QUOTECOPY_ARG\"" | \
|
2009-10-06 23:43:57 +00:00
|
|
|
${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
|
2003-07-19 10:11:54 +00:00
|
|
|
cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes"
|
|
|
|
|
2007-10-26 04:54:12 +00:00
|
|
|
rm -f "$SPACECOPY"
|
|
|
|
verbose "$tid: put filename with spaces"
|
|
|
|
echo "put $DATA ${SPACECOPY_ARG}" | \
|
2009-10-06 23:43:57 +00:00
|
|
|
${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
|
2007-10-26 04:54:12 +00:00
|
|
|
cmp $DATA "$SPACECOPY" || fail "corrupted copy after put with spaces"
|
|
|
|
|
2003-06-18 12:41:41 +00:00
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: put to directory"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "put $DATA ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 12:41:41 +00:00
|
|
|
|| fail "put failed"
|
2013-07-25 02:11:18 +00:00
|
|
|
cmp $DATA ${COPY}.dd/$DATANAME || fail "corrupted copy after put"
|
2003-06-18 12:41:41 +00:00
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: glob put to directory"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "put /bin/l? ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 12:41:41 +00:00
|
|
|
|| fail "put failed"
|
|
|
|
for x in $GLOBFILES; do
|
|
|
|
cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: put to local dir"
|
2009-10-06 23:43:57 +00:00
|
|
|
(echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 12:41:41 +00:00
|
|
|
|| fail "put failed"
|
2013-07-25 02:11:18 +00:00
|
|
|
cmp $DATA ${COPY}.dd/$DATANAME || fail "corrupted copy after put"
|
2003-06-18 12:41:41 +00:00
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: glob put to local dir"
|
2009-10-06 23:43:57 +00:00
|
|
|
(echo "cd ${COPY}.dd"; echo "put /bin/l?") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 12:41:41 +00:00
|
|
|
|| fail "put failed"
|
|
|
|
for x in $GLOBFILES; do
|
|
|
|
cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
|
|
|
|
done
|
|
|
|
|
2003-01-22 06:53:16 +00:00
|
|
|
verbose "$tid: rename"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "rename $COPY ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "rename failed"
|
|
|
|
test -f ${COPY}.1 || fail "missing file after rename"
|
|
|
|
cmp $DATA ${COPY}.1 >/dev/null 2>&1 || fail "corrupted copy after rename"
|
|
|
|
|
2003-06-18 12:35:11 +00:00
|
|
|
verbose "$tid: rename directory"
|
2007-10-26 04:54:12 +00:00
|
|
|
echo "rename ${COPY}.dd ${COPY}.dd2" | \
|
2009-10-06 23:43:57 +00:00
|
|
|
${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || \
|
2007-10-26 04:54:12 +00:00
|
|
|
fail "rename directory failed"
|
2003-06-18 12:35:11 +00:00
|
|
|
test -d ${COPY}.dd && fail "oldname exists after rename directory"
|
|
|
|
test -d ${COPY}.dd2 || fail "missing newname after rename directory"
|
|
|
|
|
2003-01-22 06:53:16 +00:00
|
|
|
verbose "$tid: ln"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed"
|
2010-12-04 22:45:50 +00:00
|
|
|
test -f ${COPY}.2 || fail "missing file after ln"
|
|
|
|
cmp ${COPY}.1 ${COPY}.2 || fail "created file is not equal after ln"
|
|
|
|
|
|
|
|
verbose "$tid: ln -s"
|
|
|
|
rm -f ${COPY}.2
|
|
|
|
echo "ln -s ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "ln -s failed"
|
|
|
|
test -h ${COPY}.2 || fail "missing file after ln -s"
|
2003-01-22 06:53:16 +00:00
|
|
|
|
2022-03-31 03:07:33 +00:00
|
|
|
verbose "$tid: cp"
|
|
|
|
rm -f ${COPY}.2
|
|
|
|
echo "cp ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "cp failed"
|
|
|
|
cmp ${COPY}.1 ${COPY}.2 || fail "created file is not equal after cp"
|
|
|
|
|
2003-01-22 06:53:16 +00:00
|
|
|
verbose "$tid: mkdir"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "mkdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "mkdir failed"
|
|
|
|
test -d ${COPY}.dd || fail "missing directory after mkdir"
|
|
|
|
|
|
|
|
# XXX do more here
|
|
|
|
verbose "$tid: chdir"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "chdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "chdir failed"
|
|
|
|
|
|
|
|
verbose "$tid: rmdir"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "rmdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "rmdir failed"
|
|
|
|
test -d ${COPY}.1 && fail "present directory after rmdir"
|
|
|
|
|
|
|
|
verbose "$tid: lmkdir"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "lmkdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "lmkdir failed"
|
|
|
|
test -d ${COPY}.dd || fail "missing directory after lmkdir"
|
|
|
|
|
|
|
|
# XXX do more here
|
|
|
|
verbose "$tid: lchdir"
|
2009-10-06 23:43:57 +00:00
|
|
|
echo "lchdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-01-22 06:53:16 +00:00
|
|
|
|| fail "lchdir failed"
|
|
|
|
|
2012-06-30 05:04:13 +00:00
|
|
|
rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
|
2007-10-26 04:54:12 +00:00
|
|
|
rm -rf ${QUOTECOPY} "$SPACECOPY" "$GLOBMETACOPY"
|
2003-01-22 06:53:16 +00:00
|
|
|
|
2009-10-06 23:43:57 +00:00
|
|
|
|