sftp-batch.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # $OpenBSD: sftp-batch.sh,v 1.5 2013/05/17 04:29:14 dtucker Exp $
  2. # Placed in the Public Domain.
  3. tid="sftp batchfile"
  4. BATCH=${OBJ}/sftp.bb
  5. rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${BATCH}.*
  6. cat << EOF > ${BATCH}.pass.1
  7. get $DATA $COPY
  8. put ${COPY} ${COPY}.1
  9. rm ${COPY}
  10. -put ${COPY} ${COPY}.2
  11. EOF
  12. cat << EOF > ${BATCH}.pass.2
  13. # This is a comment
  14. # That was a blank line
  15. ls
  16. EOF
  17. cat << EOF > ${BATCH}.fail.1
  18. get $DATA $COPY
  19. put ${COPY} ${COPY}.3
  20. rm ${COPY}.*
  21. # The next command should fail
  22. put ${COPY}.3 ${COPY}.4
  23. EOF
  24. cat << EOF > ${BATCH}.fail.2
  25. # The next command should fail
  26. jajajajaja
  27. EOF
  28. verbose "$tid: good commands"
  29. ${SFTP} -b ${BATCH}.pass.1 -D ${SFTPSERVER} > /dev/null 2>&1 ||
  30. fail "good commands failed"
  31. verbose "$tid: bad commands"
  32. ${SFTP} -b ${BATCH}.fail.1 -D ${SFTPSERVER} > /dev/null 2>&1 &&
  33. fail "bad commands succeeded"
  34. verbose "$tid: comments and blanks"
  35. ${SFTP} -b ${BATCH}.pass.2 -D ${SFTPSERVER} > /dev/null 2>&1 ||
  36. fail "comments & blanks failed"
  37. verbose "$tid: junk command"
  38. ${SFTP} -b ${BATCH}.fail.2 -D ${SFTPSERVER} > /dev/null 2>&1 &&
  39. fail "junk command succeeded"
  40. rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${BATCH}.*