sftp-uri.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # $OpenBSD: sftp-uri.sh,v 1.1 2017/10/24 19:33:32 millert Exp $
  2. # Placed in the Public Domain.
  3. tid="sftp-uri"
  4. #set -x
  5. COPY2=${OBJ}/copy2
  6. DIR=${COPY}.dd
  7. DIR2=${COPY}.dd2
  8. SRC=$(dirname ${SCRIPT})
  9. sftpclean()
  10. {
  11. rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
  12. mkdir ${DIR} ${DIR2}
  13. }
  14. start_sshd -oForceCommand="internal-sftp -d /"
  15. # Remove Port and User from ssh_config, we want to rely on the URI
  16. cp $OBJ/ssh_config $OBJ/ssh_config.orig
  17. egrep -v '^ +(Port|User) +.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config
  18. verbose "$tid: non-interactive fetch to local file"
  19. sftpclean
  20. ${SFTP} -q -S "$SSH" -F $OBJ/ssh_config "sftp://${USER}@somehost:${PORT}/${DATA}" ${COPY} || fail "copy failed"
  21. cmp ${DATA} ${COPY} || fail "corrupted copy"
  22. verbose "$tid: non-interactive fetch to local dir"
  23. sftpclean
  24. cp ${DATA} ${COPY}
  25. ${SFTP} -q -S "$SSH" -F $OBJ/ssh_config "sftp://${USER}@somehost:${PORT}/${COPY}" ${DIR} || fail "copy failed"
  26. cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
  27. verbose "$tid: put to remote directory (trailing slash)"
  28. sftpclean
  29. ${SFTP} -q -S "$SSH" -F $OBJ/ssh_config -b - \
  30. "sftp://${USER}@somehost:${PORT}/${DIR}/" > /dev/null 2>&1 << EOF
  31. version
  32. put ${DATA} copy
  33. EOF
  34. r=$?
  35. if [ $r -ne 0 ]; then
  36. fail "sftp failed with $r"
  37. else
  38. cmp ${DATA} ${DIR}/copy || fail "corrupted copy"
  39. fi
  40. verbose "$tid: put to remote directory (no slash)"
  41. sftpclean
  42. ${SFTP} -q -S "$SSH" -F $OBJ/ssh_config -b - \
  43. "sftp://${USER}@somehost:${PORT}/${DIR}" > /dev/null 2>&1 << EOF
  44. version
  45. put ${DATA} copy
  46. EOF
  47. r=$?
  48. if [ $r -ne 0 ]; then
  49. fail "sftp failed with $r"
  50. else
  51. cmp ${DATA} ${DIR}/copy || fail "corrupted copy"
  52. fi
  53. sftpclean