Friday, February 15, 2008

Network File Copy using SSH

Push: Push local file to remote server.
Pull: Pull remote file from remote server to local machine.


PUSH:

  • tar cvf - . | gzip -c -1 | ssh user@host cat ">" remotefile.gz
  • ssh target_address cat <localfile ">" remotefile
  • ssh target_address cat <localfile - ">" remotefile
  • cat localfile | ssh target_address cat ">" remotefile
  • cat localfile | ssh target_address cat - ">" remotefile
  • dd if=localfile | ssh target_address dd of=remotefile
  • ssh target_address cat <localfile "|" dd of=remotefile
  • ssh target_address cat - <localfile "|" dd of=remotefile
  • ( cd SOURCEDIR && tar cf - . ) | ssh target_address "(cd DESTDIR && tar xvpf - )"
  • ( cd SOURCEDIR && tar cvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tar )"
  • ( cd SOURCEDIR && tar czvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
  • ( cd SOURCEDIR && tar cvf - . | gzip -1 -) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
  • ssh target_address "( nc -l -p 9210 > remotefile & )" && cat source-file | gzip -1 - | nc target_address 9210
  • cat localfile | gzip -1 - | ssh target_address cat ">" remotefile.gz


PULL:
  • ssh target_address cat remotefile > localfile
  • ssh target_address dd if=remotefile | dd of=localfile
  • ssh target_address cat "<" remotefile >localfile
  • ssh target_address cat "<" remotefile.gz | gunzip >localfile

  • COMPARE:

  • ###This one uses CPU cycles on the remote server to compare the files:
  • ssh target_address cat remotefile | diff - localfile
  • cat localfile | ssh target_address diff - remotefile
  • ###This one uses CPU cycles on the local server to compare the files:
  • ssh target_address cat <localfile "|" diff - remotefile
  • No comments: