Darren Tucker | 59d928d | 2013-05-17 15:32:29 +1000 | [diff] [blame] | 1 | # $OpenBSD: sftp-batch.sh,v 1.5 2013/05/17 04:29:14 dtucker Exp $ |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="sftp batchfile" |
| 5 | |
Darren Tucker | 46662bf | 2004-01-30 13:02:55 +1100 | [diff] [blame] | 6 | BATCH=${OBJ}/sftp.bb |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 7 | |
| 8 | rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${BATCH}.* |
| 9 | |
| 10 | cat << EOF > ${BATCH}.pass.1 |
| 11 | get $DATA $COPY |
| 12 | put ${COPY} ${COPY}.1 |
| 13 | rm ${COPY} |
| 14 | -put ${COPY} ${COPY}.2 |
| 15 | EOF |
| 16 | |
| 17 | cat << EOF > ${BATCH}.pass.2 |
| 18 | # This is a comment |
| 19 | |
| 20 | # That was a blank line |
| 21 | ls |
| 22 | EOF |
| 23 | |
| 24 | cat << EOF > ${BATCH}.fail.1 |
| 25 | get $DATA $COPY |
| 26 | put ${COPY} ${COPY}.3 |
| 27 | rm ${COPY}.* |
| 28 | # The next command should fail |
| 29 | put ${COPY}.3 ${COPY}.4 |
| 30 | EOF |
| 31 | |
| 32 | cat << EOF > ${BATCH}.fail.2 |
| 33 | # The next command should fail |
| 34 | jajajajaja |
| 35 | EOF |
| 36 | |
| 37 | verbose "$tid: good commands" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 38 | ${SFTP} -b ${BATCH}.pass.1 -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 39 | || fail "good commands failed" |
| 40 | |
| 41 | verbose "$tid: bad commands" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 42 | ${SFTP} -b ${BATCH}.fail.1 -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 43 | && fail "bad commands succeeded" |
| 44 | |
| 45 | verbose "$tid: comments and blanks" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 46 | ${SFTP} -b ${BATCH}.pass.2 -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 47 | || fail "comments & blanks failed" |
| 48 | |
| 49 | verbose "$tid: junk command" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 50 | ${SFTP} -b ${BATCH}.fail.2 -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 51 | && fail "junk command succeeded" |
| 52 | |
| 53 | rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${BATCH}.* |
| 54 | |
| 55 | |