2003-10-08 09:52:10 +02:00
|
|
|
# $OpenBSD: sftp-cmds.sh,v 1.6 2003/10/07 07:04:52 djm Exp $
|
2003-01-22 07:53:16 +01:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
# XXX - TODO:
|
|
|
|
# - chmod / chown / chgrp
|
|
|
|
# - -p flag for get & put
|
|
|
|
|
|
|
|
tid="sftp commands"
|
|
|
|
|
2003-09-04 06:54:39 +02:00
|
|
|
DATA=/bin/ls${EXEEXT}
|
2003-01-22 07:53:16 +01:00
|
|
|
COPY=${OBJ}/copy
|
2003-09-04 06:26:31 +02: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-09-12 07:32:17 +02:00
|
|
|
if have_prog uname
|
2003-09-07 01:32:58 +02:00
|
|
|
then
|
|
|
|
case `uname` in
|
|
|
|
CYGWIN*)
|
|
|
|
os=cygwin
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
os=`uname`
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
os="unknown"
|
|
|
|
fi
|
|
|
|
|
2003-07-19 12:11:54 +02:00
|
|
|
# Path with embedded quote
|
|
|
|
QUOTECOPY=${COPY}".\"blah\""
|
|
|
|
QUOTECOPY_ARG=${COPY}'.\"blah\"'
|
|
|
|
|
2003-09-09 17:35:20 +02:00
|
|
|
rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
|
2003-06-18 14:41:41 +02:00
|
|
|
mkdir ${COPY}.dd
|
2003-01-22 07:53:16 +01:00
|
|
|
|
|
|
|
verbose "$tid: lls"
|
|
|
|
echo "lls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "lls failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: ls"
|
|
|
|
echo "ls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "ls failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: shell"
|
|
|
|
echo "!echo hi there" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "shell failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: pwd"
|
|
|
|
echo "pwd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "pwd failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: lpwd"
|
|
|
|
echo "lpwd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "lpwd failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: quit"
|
|
|
|
echo "quit" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "quit failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
verbose "$tid: help"
|
|
|
|
echo "help" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "help failed"
|
|
|
|
# XXX always successful
|
|
|
|
|
|
|
|
rm -f ${COPY}
|
|
|
|
verbose "$tid: get"
|
|
|
|
echo "get $DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "get failed"
|
|
|
|
cmp $DATA ${COPY} || fail "corrupted copy after get"
|
|
|
|
|
2003-10-08 09:52:10 +02:00
|
|
|
rm -f ${COPY}
|
|
|
|
verbose "$tid: get quoted"
|
|
|
|
echo "get \"$DATA\" $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "get failed"
|
|
|
|
cmp $DATA ${COPY} || fail "corrupted copy after get"
|
|
|
|
|
2004-04-16 09:58:28 +02:00
|
|
|
if [ "$os" != "cygwin" ]; then
|
2003-10-08 09:52:10 +02:00
|
|
|
rm -f ${QUOTECOPY}
|
|
|
|
cp $DATA ${QUOTECOPY}
|
|
|
|
verbose "$tid: get filename with quotes"
|
|
|
|
echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "put failed"
|
|
|
|
cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes"
|
|
|
|
rm -f ${QUOTECOPY} ${COPY}
|
2004-04-16 09:58:28 +02:00
|
|
|
fi
|
2003-10-08 09:52:10 +02:00
|
|
|
|
2003-06-18 14:41:41 +02:00
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: get to directory"
|
|
|
|
echo "get $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "get failed"
|
2003-09-04 06:54:39 +02:00
|
|
|
cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get"
|
2003-06-18 14:41:41 +02:00
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: glob get to directory"
|
|
|
|
echo "get /bin/l* ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| 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"
|
2003-09-04 06:54:39 +02:00
|
|
|
(echo "lcd ${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 14:41:41 +02:00
|
|
|
|| fail "get failed"
|
2003-09-04 06:54:39 +02:00
|
|
|
cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get"
|
2003-06-18 14:41:41 +02:00
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: glob get to local dir"
|
2003-09-04 06:54:39 +02:00
|
|
|
(echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 14:41:41 +02:00
|
|
|
|| fail "get failed"
|
|
|
|
for x in $GLOBFILES; do
|
|
|
|
cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
|
|
|
|
done
|
|
|
|
|
2003-01-22 07:53:16 +01:00
|
|
|
rm -f ${COPY}
|
|
|
|
verbose "$tid: put"
|
|
|
|
echo "put $DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "put failed"
|
|
|
|
cmp $DATA ${COPY} || fail "corrupted copy after put"
|
|
|
|
|
2003-09-07 01:32:58 +02:00
|
|
|
if [ "$os" != "cygwin" ]; then
|
2003-07-19 12:11:54 +02:00
|
|
|
rm -f ${QUOTECOPY}
|
|
|
|
verbose "$tid: put filename with quotes"
|
|
|
|
echo "put $DATA \"$QUOTECOPY_ARG\"" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "put failed"
|
|
|
|
cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes"
|
2003-09-07 01:32:58 +02:00
|
|
|
fi
|
2003-07-19 12:11:54 +02:00
|
|
|
|
2003-06-18 14:41:41 +02:00
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: put to directory"
|
|
|
|
echo "put $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "put failed"
|
2003-09-04 06:54:39 +02:00
|
|
|
cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put"
|
2003-06-18 14:41:41 +02:00
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: glob put to directory"
|
|
|
|
echo "put /bin/l* ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| 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"
|
2003-09-04 06:54:39 +02:00
|
|
|
(echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 14:41:41 +02:00
|
|
|
|| fail "put failed"
|
2003-09-04 06:54:39 +02:00
|
|
|
cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put"
|
2003-06-18 14:41:41 +02:00
|
|
|
|
|
|
|
rm -f ${COPY}.dd/*
|
|
|
|
verbose "$tid: glob put to local dir"
|
2003-09-04 06:54:39 +02:00
|
|
|
(echo "cd ${COPY}.dd"; echo "put /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
2003-06-18 14:41:41 +02:00
|
|
|
|| fail "put failed"
|
|
|
|
for x in $GLOBFILES; do
|
|
|
|
cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
|
|
|
|
done
|
|
|
|
|
2003-01-22 07:53:16 +01:00
|
|
|
verbose "$tid: rename"
|
|
|
|
echo "rename $COPY ${COPY}.1" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| 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 14:35:11 +02:00
|
|
|
verbose "$tid: rename directory"
|
|
|
|
echo "rename ${COPY}.dd ${COPY}.dd2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "rename directory failed"
|
|
|
|
test -d ${COPY}.dd && fail "oldname exists after rename directory"
|
|
|
|
test -d ${COPY}.dd2 || fail "missing newname after rename directory"
|
|
|
|
|
2003-01-22 07:53:16 +01:00
|
|
|
verbose "$tid: ln"
|
|
|
|
echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed"
|
2003-09-04 07:24:50 +02:00
|
|
|
test -h ${COPY}.2 || fail "missing file after ln"
|
2003-01-22 07:53:16 +01:00
|
|
|
|
|
|
|
verbose "$tid: mkdir"
|
|
|
|
echo "mkdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "mkdir failed"
|
|
|
|
test -d ${COPY}.dd || fail "missing directory after mkdir"
|
|
|
|
|
|
|
|
# XXX do more here
|
|
|
|
verbose "$tid: chdir"
|
|
|
|
echo "chdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "chdir failed"
|
|
|
|
|
|
|
|
verbose "$tid: rmdir"
|
|
|
|
echo "rmdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "rmdir failed"
|
|
|
|
test -d ${COPY}.1 && fail "present directory after rmdir"
|
|
|
|
|
|
|
|
verbose "$tid: lmkdir"
|
|
|
|
echo "lmkdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "lmkdir failed"
|
|
|
|
test -d ${COPY}.dd || fail "missing directory after lmkdir"
|
|
|
|
|
|
|
|
# XXX do more here
|
|
|
|
verbose "$tid: lchdir"
|
|
|
|
echo "lchdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
|
|
|
|
|| fail "lchdir failed"
|
|
|
|
|
2003-09-09 17:35:20 +02:00
|
|
|
rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
|
2003-01-22 07:53:16 +01:00
|
|
|
|
|
|
|
|