scp-uri.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # $OpenBSD: scp-uri.sh,v 1.2 2017/12/11 11:41:56 dtucker Exp $
  2. # Placed in the Public Domain.
  3. tid="scp-uri"
  4. #set -x
  5. COPY2=${OBJ}/copy2
  6. DIR=${COPY}.dd
  7. DIR2=${COPY}.dd2
  8. SRC=$(dirname ${SCRIPT})
  9. cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
  10. chmod 755 ${OBJ}/scp-ssh-wrapper.scp
  11. scpopts="-q -S ${OBJ}/scp-ssh-wrapper.scp"
  12. export SCP # used in scp-ssh-wrapper.scp
  13. scpclean()
  14. {
  15. rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
  16. mkdir ${DIR} ${DIR2}
  17. }
  18. # Remove Port and User from ssh_config, we want to rely on the URI
  19. cp $OBJ/ssh_config $OBJ/ssh_config.orig
  20. egrep -v '^ +(Port|User) +.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config
  21. verbose "$tid: simple copy local file to remote file"
  22. scpclean
  23. $SCP $scpopts ${DATA} "scp://${USER}@somehost:${PORT}/${COPY}" || fail "copy failed"
  24. cmp ${DATA} ${COPY} || fail "corrupted copy"
  25. verbose "$tid: simple copy remote file to local file"
  26. scpclean
  27. $SCP $scpopts "scp://${USER}@somehost:${PORT}/${DATA}" ${COPY} || fail "copy failed"
  28. cmp ${DATA} ${COPY} || fail "corrupted copy"
  29. verbose "$tid: simple copy local file to remote dir"
  30. scpclean
  31. cp ${DATA} ${COPY}
  32. $SCP $scpopts ${COPY} "scp://${USER}@somehost:${PORT}/${DIR}" || fail "copy failed"
  33. cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
  34. verbose "$tid: simple copy remote file to local dir"
  35. scpclean
  36. cp ${DATA} ${COPY}
  37. $SCP $scpopts "scp://${USER}@somehost:${PORT}/${COPY}" ${DIR} || fail "copy failed"
  38. cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
  39. verbose "$tid: recursive local dir to remote dir"
  40. scpclean
  41. rm -rf ${DIR2}
  42. cp ${DATA} ${DIR}/copy
  43. $SCP $scpopts -r ${DIR} "scp://${USER}@somehost:${PORT}/${DIR2}" || fail "copy failed"
  44. for i in $(cd ${DIR} && echo *); do
  45. cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy"
  46. done
  47. verbose "$tid: recursive remote dir to local dir"
  48. scpclean
  49. rm -rf ${DIR2}
  50. cp ${DATA} ${DIR}/copy
  51. $SCP $scpopts -r "scp://${USER}@somehost:${PORT}/${DIR}" ${DIR2} || fail "copy failed"
  52. for i in $(cd ${DIR} && echo *); do
  53. cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy"
  54. done
  55. # TODO: scp -3
  56. scpclean
  57. rm -f ${OBJ}/scp-ssh-wrapper.exe