I need to copy all the .class files from server to local with all dir reserved. e.g. server:/usr/some/unknown/number/of/sub/folders/me.class
will be /usr/project/backup/some/unknown/number/of/sub/folders/me.class
the problem is, there are many other useless files such as .svn-base files that i don't want. how can i filter them so I only scp
.class files?
To copy a directory (and all the files it contains), use scp with the -r option. This tells scp to recursively copy the source directory and its contents. You'll be prompted for your password on the source system ( deathstar.com ). The command won't work unless you enter the correct password.
Copying files and directories with SCP or Rsync Secure Copy (SCP) uses SSH to copy only the files or directories that you select. On first use, Rsync copies all files and directories and then it copies only the files and directories that you have changed. It does not copy all the files and directories again.
The Unix command scp (which stands for "secure copy protocol") is a simple tool for uploading or downloading files (or directories) to/from a remote machine.
The scp tool relies on SSH (Secure Shell) to transfer files, so all you need is the username and password for the source and target systems. Another advantage is that with SCP you can move files between two remote servers, from your local machine in addition to transferring data between local and remote machines.
I'd probably recommend using something like rsync
for this due to its include
and exclude
flags, e.g:-
rsync -rav -e ssh --include '*/' --include='*.class' --exclude='*' \ server:/usr/some/unknown/number/of/sub/folders/ \ /usr/project/backup/some/unknown/number/of/sub/folders/
Some other useful flags:
-r
for recursive-a
for archive (mostly all files)-v
for verbose output-e
to specify ssh instead of the default (which should be ssh, actually)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With