Can scp copy directories recursively?How to copy certain file with its path from remote to my local machine via scp?How to make scp copy hidden files?How do I do Multihop SCP transfers?Problems with SCP stalling during file copy over VPNVariable directory names over SCPQuickest way to transfer 55GB of images to new serverUbuntu SCP copy stallsHow to _MOVE_ files with scp?Can scp maintain original file structure on remote server?scp to copy file to remote server fails because of permissionsscp blocked at `debug1: Sending command: scp -v -f scp-test`

Conflicting terms and the definition of a «child»

If Earth is tilted, why is Polaris always above the same spot?

Unidentified items in bicycle tube repair kit

What was the state of the German rail system in 1944?

Accidentally deleted the "/usr/share" folder

If I supply 24v to a 50v rated 22000uf electrolytic capacitor, does that mean it will store 44000uf at 24v?

Field Length Validation for Desktop Application which has maximum 1000 characters

Game of Life meets Chaos Theory

Feels like I am getting dragged into office politics

Does the time required to copy a spell into a spellbook have to be consecutive, or is that just the cumulative time required?

How to assert on pagereference where the endpoint of pagereference is predefined

Why do freehub and cassette have only one position that matches?

When and why did journal article titles become descriptive, rather than creatively allusive?

Why is Arya visibly scared in the library in S8E3?

Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?

How to creep the reader out with what seems like a normal person?

Geometry - Proving a common centroid.

Why was Germany not as successful as other Europeans in establishing overseas colonies?

Historically, were women trained for obligatory wars? Or did they serve some other military function?

An 'if constexpr branch' does not get discarded inside lambda that is inside a template function

I lost my Irish passport. Can I travel to Thailand and back from the UK using my US passport?

How to get SEEK accessing converted ID via view

When do aircrafts become solarcrafts?

How to avoid grep command finding commented out strings in the source file?



Can scp copy directories recursively?


How to copy certain file with its path from remote to my local machine via scp?How to make scp copy hidden files?How do I do Multihop SCP transfers?Problems with SCP stalling during file copy over VPNVariable directory names over SCPQuickest way to transfer 55GB of images to new serverUbuntu SCP copy stallsHow to _MOVE_ files with scp?Can scp maintain original file structure on remote server?scp to copy file to remote server fails because of permissionsscp blocked at `debug1: Sending command: scp -v -f scp-test`






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








559















Currently I can only copy a single .tar file. But how can I copy directories recursively with scp?










share|improve this question






























    559















    Currently I can only copy a single .tar file. But how can I copy directories recursively with scp?










    share|improve this question


























      559












      559








      559


      129






      Currently I can only copy a single .tar file. But how can I copy directories recursively with scp?










      share|improve this question
















      Currently I can only copy a single .tar file. But how can I copy directories recursively with scp?







      linux scp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 10 '18 at 15:19









      U880D

      381414




      381414










      asked Apr 29 '11 at 4:24









      kernelkernel

      3,07341514




      3,07341514




















          10 Answers
          10






          active

          oldest

          votes


















          907














          Yup, use -r:



          scp -rp sourcedirectory user@dest:/path


          • -r means recursive

          • -p preserves modification times, access times, and modes from the original file.

          Note: This creates the sourcedirectory inside /path thus the files will be in /path/sourcedirectory






          share|improve this answer




















          • 9





            However bear in mind that this won't preserve symlinks.

            – CpnCrunch
            Jul 24 '15 at 0:30






          • 11





            Note that -pr (options in reversed order) won't copy the folders, bur rather their content to the target directory (apparently, the order of options matters).

            – pms
            Feb 3 '17 at 14:49











          • For some reason /path appears to be relative to the users $HOME -- how do I make it absolute without being root@?

            – Jonathan
            Aug 25 '17 at 21:50












          • Yeah, SCP like never puts the files where I want. Often when trying to replace a directory, I somehow end up with another directory inside it with the same name instead. I'm extra careful with this.

            – sudo
            Jan 24 '18 at 3:00












          • thank you, a dev environment limits me from using rsync (not built into the end node's functionality). So I find the other answers a little detracting.

            – thistleknot
            Feb 5 at 18:41


















          159














          While the previous answers are technically correct, you should also consider using rsync instead. rsync compares the data on the sending and receiving sides with a diff mechanism so it doesn't have to resend data that was already previously sent.



          If you are going to copy something to a remote machine more than once, use rsync. Actually, it's good to use rsync every time because it has more controls for things like copying file permissions and ownership and excluding certain files or directories. In general:



          $ rsync -av /local/dir/ server:/remote/dir/


          will synchronize a local directory with a remote directory. If you run it a second time and the contents of the local directory haven't changed, no data will be transferred - much more efficient than running scp and copying everything every time.



          Also, rsync allows you to recover from interrupted transfers very easily, unlike scp.



          Finally, modern versions of rsync by default run over ssh, so if scp is already working, rsync should pretty much be a drop-in replacement.






          share|improve this answer




















          • 13





            "no data will be transferred" except, of course, the data required to determine exactly what has or has not changed.

            – thsutton
            Apr 29 '11 at 5:15






          • 14





            Ha yeah I glossed that over a bit obviously. We're not talking quantum entanglement here.

            – Phil Hollenback
            Apr 29 '11 at 6:01






          • 2





            it's so sad that osx, win7 and not even ubuntu uses something like rsync for their GUI yet.

            – cregox
            Apr 29 '11 at 10:24






          • 11





            dmourati I did answer his question. I told him a better way to do it.

            – Phil Hollenback
            Jan 29 '13 at 21:23






          • 2





            @raphnguyen: no, deleting files from the local directory will not delete them from the remote directory. You can turn this behavior on with the --delete rsync option.

            – Phil Hollenback
            Oct 26 '15 at 20:19


















          32














          That is what the -r option is for. :)



          See the scp man page for more info if needed.






          share|improve this answer






























            10














            Recursive Copy Option '-r' (lower case)



            scp -r


            Which I confuse with the regular local recursive copy option '-R' (upper case)



            cp -R





            share|improve this answer


















            • 1





              I just wanted to point out the difference between cp and scp as -r and -R are not the same. unix.stackexchange.com/questions/18712/…

              – Tarun
              Sep 23 '13 at 14:54



















            5














            The best way is to use rsync over SSH



            rsync -a -essh /source/ user@dest-server:/dest/

            rsync -a -essh user@source-server:/source/ /dest/


            My favorites options are -Pazvessh --delete :



            • -a : archive mode (include a lot of default common options, including preserving symlinks)

            • -z : compress

            • -v : verbose : show files

            • -P : show progess as files done/remaining files

            • -e ssh : do rsync in ssh protocol

            • --delete : delete files in the destination that are not anymore in the source





            share|improve this answer























            • All versions of rsync that I have used would use ssh by default, so -essh is unlikely to be needed. And the choice of command used to connect to the remote host is really unrelated to copying recursively.

              – kasperd
              Nov 5 '15 at 19:03


















            4














            After looking for the recursive copy flag, and successfully used it thanks to this post, I would like to post just a suggestion.



            If the case is that you are copying (recursively) a directory. Maybe if the files are sent compressed you could save time in the transfer



            What I did in the end was:



            local$ tar -czvf local.tar.gz directory/
            local$ scp local.tar.gz user@remote:/directory
            ssh user@remote
            remote$ tar -xzvf local.tar.gz


            Hope this helps






            share|improve this answer

























            • the file extension should be either .tar.gz or .tgz since the file is a gzipped tar archive (since the -z flag is used).

              – anthonybell
              Mar 26 '18 at 22:07


















            2














            You can recursively copy a directory into a compressed archive with this simple command:



            ssh -p 22 user@address-to-copy-from.com 'cd /parent/directory && tar zcvf - directory_to_copy' > /destination/on/your/machine/archive_name.tgz


            For example, to copy contents of /var/log from domain.com to ~/logs.tgz you run:



            ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' > ~/logs.tgz


            You can also extract files on target system by using pipes. This command will copy contents of /var/log at domain.com to ~/destination/log on your system:



            ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' | tar xzf - -C ~/destination


            Though to mirror a directory, you probably should use rsync...






            share|improve this answer
































              1














              If you prefer to pass the user's password as a parameter rather than inputting it interactively, you can use sshpass (sudo apt-get install -y sshpass).



              Example:



              sshpass -p 'remote_password' scp -rp /src/folder myremoteusername@122.10.12.123:/dest/folder





              share|improve this answer






























                0














                You can use -r option with scp command to copy directories recursively on any system. If you need anything else refer scp command tutorial. -r option stands for recursive operation in most of the Linux commands.






                share|improve this answer























                • While true, the -r option has already been suggested years ago and is the accepted answer.

                  – RalfFriedl
                  Apr 22 at 16:05


















                -3














                Another (likely better for repeated use) option is to use NFS - check out nfs-kernel-server and how to setup NFS shares.






                share|improve this answer


















                • 2





                  This is complete nonsense. There are endless cases where you would use scp but NFS is not an option.

                  – Sven
                  Aug 11 '16 at 23:24











                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "2"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f264595%2fcan-scp-copy-directories-recursively%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                10 Answers
                10






                active

                oldest

                votes








                10 Answers
                10






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                907














                Yup, use -r:



                scp -rp sourcedirectory user@dest:/path


                • -r means recursive

                • -p preserves modification times, access times, and modes from the original file.

                Note: This creates the sourcedirectory inside /path thus the files will be in /path/sourcedirectory






                share|improve this answer




















                • 9





                  However bear in mind that this won't preserve symlinks.

                  – CpnCrunch
                  Jul 24 '15 at 0:30






                • 11





                  Note that -pr (options in reversed order) won't copy the folders, bur rather their content to the target directory (apparently, the order of options matters).

                  – pms
                  Feb 3 '17 at 14:49











                • For some reason /path appears to be relative to the users $HOME -- how do I make it absolute without being root@?

                  – Jonathan
                  Aug 25 '17 at 21:50












                • Yeah, SCP like never puts the files where I want. Often when trying to replace a directory, I somehow end up with another directory inside it with the same name instead. I'm extra careful with this.

                  – sudo
                  Jan 24 '18 at 3:00












                • thank you, a dev environment limits me from using rsync (not built into the end node's functionality). So I find the other answers a little detracting.

                  – thistleknot
                  Feb 5 at 18:41















                907














                Yup, use -r:



                scp -rp sourcedirectory user@dest:/path


                • -r means recursive

                • -p preserves modification times, access times, and modes from the original file.

                Note: This creates the sourcedirectory inside /path thus the files will be in /path/sourcedirectory






                share|improve this answer




















                • 9





                  However bear in mind that this won't preserve symlinks.

                  – CpnCrunch
                  Jul 24 '15 at 0:30






                • 11





                  Note that -pr (options in reversed order) won't copy the folders, bur rather their content to the target directory (apparently, the order of options matters).

                  – pms
                  Feb 3 '17 at 14:49











                • For some reason /path appears to be relative to the users $HOME -- how do I make it absolute without being root@?

                  – Jonathan
                  Aug 25 '17 at 21:50












                • Yeah, SCP like never puts the files where I want. Often when trying to replace a directory, I somehow end up with another directory inside it with the same name instead. I'm extra careful with this.

                  – sudo
                  Jan 24 '18 at 3:00












                • thank you, a dev environment limits me from using rsync (not built into the end node's functionality). So I find the other answers a little detracting.

                  – thistleknot
                  Feb 5 at 18:41













                907












                907








                907







                Yup, use -r:



                scp -rp sourcedirectory user@dest:/path


                • -r means recursive

                • -p preserves modification times, access times, and modes from the original file.

                Note: This creates the sourcedirectory inside /path thus the files will be in /path/sourcedirectory






                share|improve this answer















                Yup, use -r:



                scp -rp sourcedirectory user@dest:/path


                • -r means recursive

                • -p preserves modification times, access times, and modes from the original file.

                Note: This creates the sourcedirectory inside /path thus the files will be in /path/sourcedirectory







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 4 '17 at 10:20









                Abel Melquiades Callejo

                1157




                1157










                answered Apr 29 '11 at 4:28









                dmouratidmourati

                20.1k22864




                20.1k22864







                • 9





                  However bear in mind that this won't preserve symlinks.

                  – CpnCrunch
                  Jul 24 '15 at 0:30






                • 11





                  Note that -pr (options in reversed order) won't copy the folders, bur rather their content to the target directory (apparently, the order of options matters).

                  – pms
                  Feb 3 '17 at 14:49











                • For some reason /path appears to be relative to the users $HOME -- how do I make it absolute without being root@?

                  – Jonathan
                  Aug 25 '17 at 21:50












                • Yeah, SCP like never puts the files where I want. Often when trying to replace a directory, I somehow end up with another directory inside it with the same name instead. I'm extra careful with this.

                  – sudo
                  Jan 24 '18 at 3:00












                • thank you, a dev environment limits me from using rsync (not built into the end node's functionality). So I find the other answers a little detracting.

                  – thistleknot
                  Feb 5 at 18:41












                • 9





                  However bear in mind that this won't preserve symlinks.

                  – CpnCrunch
                  Jul 24 '15 at 0:30






                • 11





                  Note that -pr (options in reversed order) won't copy the folders, bur rather their content to the target directory (apparently, the order of options matters).

                  – pms
                  Feb 3 '17 at 14:49











                • For some reason /path appears to be relative to the users $HOME -- how do I make it absolute without being root@?

                  – Jonathan
                  Aug 25 '17 at 21:50












                • Yeah, SCP like never puts the files where I want. Often when trying to replace a directory, I somehow end up with another directory inside it with the same name instead. I'm extra careful with this.

                  – sudo
                  Jan 24 '18 at 3:00












                • thank you, a dev environment limits me from using rsync (not built into the end node's functionality). So I find the other answers a little detracting.

                  – thistleknot
                  Feb 5 at 18:41







                9




                9





                However bear in mind that this won't preserve symlinks.

                – CpnCrunch
                Jul 24 '15 at 0:30





                However bear in mind that this won't preserve symlinks.

                – CpnCrunch
                Jul 24 '15 at 0:30




                11




                11





                Note that -pr (options in reversed order) won't copy the folders, bur rather their content to the target directory (apparently, the order of options matters).

                – pms
                Feb 3 '17 at 14:49





                Note that -pr (options in reversed order) won't copy the folders, bur rather their content to the target directory (apparently, the order of options matters).

                – pms
                Feb 3 '17 at 14:49













                For some reason /path appears to be relative to the users $HOME -- how do I make it absolute without being root@?

                – Jonathan
                Aug 25 '17 at 21:50






                For some reason /path appears to be relative to the users $HOME -- how do I make it absolute without being root@?

                – Jonathan
                Aug 25 '17 at 21:50














                Yeah, SCP like never puts the files where I want. Often when trying to replace a directory, I somehow end up with another directory inside it with the same name instead. I'm extra careful with this.

                – sudo
                Jan 24 '18 at 3:00






                Yeah, SCP like never puts the files where I want. Often when trying to replace a directory, I somehow end up with another directory inside it with the same name instead. I'm extra careful with this.

                – sudo
                Jan 24 '18 at 3:00














                thank you, a dev environment limits me from using rsync (not built into the end node's functionality). So I find the other answers a little detracting.

                – thistleknot
                Feb 5 at 18:41





                thank you, a dev environment limits me from using rsync (not built into the end node's functionality). So I find the other answers a little detracting.

                – thistleknot
                Feb 5 at 18:41













                159














                While the previous answers are technically correct, you should also consider using rsync instead. rsync compares the data on the sending and receiving sides with a diff mechanism so it doesn't have to resend data that was already previously sent.



                If you are going to copy something to a remote machine more than once, use rsync. Actually, it's good to use rsync every time because it has more controls for things like copying file permissions and ownership and excluding certain files or directories. In general:



                $ rsync -av /local/dir/ server:/remote/dir/


                will synchronize a local directory with a remote directory. If you run it a second time and the contents of the local directory haven't changed, no data will be transferred - much more efficient than running scp and copying everything every time.



                Also, rsync allows you to recover from interrupted transfers very easily, unlike scp.



                Finally, modern versions of rsync by default run over ssh, so if scp is already working, rsync should pretty much be a drop-in replacement.






                share|improve this answer




















                • 13





                  "no data will be transferred" except, of course, the data required to determine exactly what has or has not changed.

                  – thsutton
                  Apr 29 '11 at 5:15






                • 14





                  Ha yeah I glossed that over a bit obviously. We're not talking quantum entanglement here.

                  – Phil Hollenback
                  Apr 29 '11 at 6:01






                • 2





                  it's so sad that osx, win7 and not even ubuntu uses something like rsync for their GUI yet.

                  – cregox
                  Apr 29 '11 at 10:24






                • 11





                  dmourati I did answer his question. I told him a better way to do it.

                  – Phil Hollenback
                  Jan 29 '13 at 21:23






                • 2





                  @raphnguyen: no, deleting files from the local directory will not delete them from the remote directory. You can turn this behavior on with the --delete rsync option.

                  – Phil Hollenback
                  Oct 26 '15 at 20:19















                159














                While the previous answers are technically correct, you should also consider using rsync instead. rsync compares the data on the sending and receiving sides with a diff mechanism so it doesn't have to resend data that was already previously sent.



                If you are going to copy something to a remote machine more than once, use rsync. Actually, it's good to use rsync every time because it has more controls for things like copying file permissions and ownership and excluding certain files or directories. In general:



                $ rsync -av /local/dir/ server:/remote/dir/


                will synchronize a local directory with a remote directory. If you run it a second time and the contents of the local directory haven't changed, no data will be transferred - much more efficient than running scp and copying everything every time.



                Also, rsync allows you to recover from interrupted transfers very easily, unlike scp.



                Finally, modern versions of rsync by default run over ssh, so if scp is already working, rsync should pretty much be a drop-in replacement.






                share|improve this answer




















                • 13





                  "no data will be transferred" except, of course, the data required to determine exactly what has or has not changed.

                  – thsutton
                  Apr 29 '11 at 5:15






                • 14





                  Ha yeah I glossed that over a bit obviously. We're not talking quantum entanglement here.

                  – Phil Hollenback
                  Apr 29 '11 at 6:01






                • 2





                  it's so sad that osx, win7 and not even ubuntu uses something like rsync for their GUI yet.

                  – cregox
                  Apr 29 '11 at 10:24






                • 11





                  dmourati I did answer his question. I told him a better way to do it.

                  – Phil Hollenback
                  Jan 29 '13 at 21:23






                • 2





                  @raphnguyen: no, deleting files from the local directory will not delete them from the remote directory. You can turn this behavior on with the --delete rsync option.

                  – Phil Hollenback
                  Oct 26 '15 at 20:19













                159












                159








                159







                While the previous answers are technically correct, you should also consider using rsync instead. rsync compares the data on the sending and receiving sides with a diff mechanism so it doesn't have to resend data that was already previously sent.



                If you are going to copy something to a remote machine more than once, use rsync. Actually, it's good to use rsync every time because it has more controls for things like copying file permissions and ownership and excluding certain files or directories. In general:



                $ rsync -av /local/dir/ server:/remote/dir/


                will synchronize a local directory with a remote directory. If you run it a second time and the contents of the local directory haven't changed, no data will be transferred - much more efficient than running scp and copying everything every time.



                Also, rsync allows you to recover from interrupted transfers very easily, unlike scp.



                Finally, modern versions of rsync by default run over ssh, so if scp is already working, rsync should pretty much be a drop-in replacement.






                share|improve this answer















                While the previous answers are technically correct, you should also consider using rsync instead. rsync compares the data on the sending and receiving sides with a diff mechanism so it doesn't have to resend data that was already previously sent.



                If you are going to copy something to a remote machine more than once, use rsync. Actually, it's good to use rsync every time because it has more controls for things like copying file permissions and ownership and excluding certain files or directories. In general:



                $ rsync -av /local/dir/ server:/remote/dir/


                will synchronize a local directory with a remote directory. If you run it a second time and the contents of the local directory haven't changed, no data will be transferred - much more efficient than running scp and copying everything every time.



                Also, rsync allows you to recover from interrupted transfers very easily, unlike scp.



                Finally, modern versions of rsync by default run over ssh, so if scp is already working, rsync should pretty much be a drop-in replacement.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Sep 8 '16 at 23:27









                phyatt

                1034




                1034










                answered Apr 29 '11 at 5:11









                Phil HollenbackPhil Hollenback

                12.8k32649




                12.8k32649







                • 13





                  "no data will be transferred" except, of course, the data required to determine exactly what has or has not changed.

                  – thsutton
                  Apr 29 '11 at 5:15






                • 14





                  Ha yeah I glossed that over a bit obviously. We're not talking quantum entanglement here.

                  – Phil Hollenback
                  Apr 29 '11 at 6:01






                • 2





                  it's so sad that osx, win7 and not even ubuntu uses something like rsync for their GUI yet.

                  – cregox
                  Apr 29 '11 at 10:24






                • 11





                  dmourati I did answer his question. I told him a better way to do it.

                  – Phil Hollenback
                  Jan 29 '13 at 21:23






                • 2





                  @raphnguyen: no, deleting files from the local directory will not delete them from the remote directory. You can turn this behavior on with the --delete rsync option.

                  – Phil Hollenback
                  Oct 26 '15 at 20:19












                • 13





                  "no data will be transferred" except, of course, the data required to determine exactly what has or has not changed.

                  – thsutton
                  Apr 29 '11 at 5:15






                • 14





                  Ha yeah I glossed that over a bit obviously. We're not talking quantum entanglement here.

                  – Phil Hollenback
                  Apr 29 '11 at 6:01






                • 2





                  it's so sad that osx, win7 and not even ubuntu uses something like rsync for their GUI yet.

                  – cregox
                  Apr 29 '11 at 10:24






                • 11





                  dmourati I did answer his question. I told him a better way to do it.

                  – Phil Hollenback
                  Jan 29 '13 at 21:23






                • 2





                  @raphnguyen: no, deleting files from the local directory will not delete them from the remote directory. You can turn this behavior on with the --delete rsync option.

                  – Phil Hollenback
                  Oct 26 '15 at 20:19







                13




                13





                "no data will be transferred" except, of course, the data required to determine exactly what has or has not changed.

                – thsutton
                Apr 29 '11 at 5:15





                "no data will be transferred" except, of course, the data required to determine exactly what has or has not changed.

                – thsutton
                Apr 29 '11 at 5:15




                14




                14





                Ha yeah I glossed that over a bit obviously. We're not talking quantum entanglement here.

                – Phil Hollenback
                Apr 29 '11 at 6:01





                Ha yeah I glossed that over a bit obviously. We're not talking quantum entanglement here.

                – Phil Hollenback
                Apr 29 '11 at 6:01




                2




                2





                it's so sad that osx, win7 and not even ubuntu uses something like rsync for their GUI yet.

                – cregox
                Apr 29 '11 at 10:24





                it's so sad that osx, win7 and not even ubuntu uses something like rsync for their GUI yet.

                – cregox
                Apr 29 '11 at 10:24




                11




                11





                dmourati I did answer his question. I told him a better way to do it.

                – Phil Hollenback
                Jan 29 '13 at 21:23





                dmourati I did answer his question. I told him a better way to do it.

                – Phil Hollenback
                Jan 29 '13 at 21:23




                2




                2





                @raphnguyen: no, deleting files from the local directory will not delete them from the remote directory. You can turn this behavior on with the --delete rsync option.

                – Phil Hollenback
                Oct 26 '15 at 20:19





                @raphnguyen: no, deleting files from the local directory will not delete them from the remote directory. You can turn this behavior on with the --delete rsync option.

                – Phil Hollenback
                Oct 26 '15 at 20:19











                32














                That is what the -r option is for. :)



                See the scp man page for more info if needed.






                share|improve this answer



























                  32














                  That is what the -r option is for. :)



                  See the scp man page for more info if needed.






                  share|improve this answer

























                    32












                    32








                    32







                    That is what the -r option is for. :)



                    See the scp man page for more info if needed.






                    share|improve this answer













                    That is what the -r option is for. :)



                    See the scp man page for more info if needed.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 29 '11 at 4:27









                    HedgeMageHedgeMage

                    42339




                    42339





















                        10














                        Recursive Copy Option '-r' (lower case)



                        scp -r


                        Which I confuse with the regular local recursive copy option '-R' (upper case)



                        cp -R





                        share|improve this answer


















                        • 1





                          I just wanted to point out the difference between cp and scp as -r and -R are not the same. unix.stackexchange.com/questions/18712/…

                          – Tarun
                          Sep 23 '13 at 14:54
















                        10














                        Recursive Copy Option '-r' (lower case)



                        scp -r


                        Which I confuse with the regular local recursive copy option '-R' (upper case)



                        cp -R





                        share|improve this answer


















                        • 1





                          I just wanted to point out the difference between cp and scp as -r and -R are not the same. unix.stackexchange.com/questions/18712/…

                          – Tarun
                          Sep 23 '13 at 14:54














                        10












                        10








                        10







                        Recursive Copy Option '-r' (lower case)



                        scp -r


                        Which I confuse with the regular local recursive copy option '-R' (upper case)



                        cp -R





                        share|improve this answer













                        Recursive Copy Option '-r' (lower case)



                        scp -r


                        Which I confuse with the regular local recursive copy option '-R' (upper case)



                        cp -R






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Sep 11 '13 at 17:53









                        TarunTarun

                        20123




                        20123







                        • 1





                          I just wanted to point out the difference between cp and scp as -r and -R are not the same. unix.stackexchange.com/questions/18712/…

                          – Tarun
                          Sep 23 '13 at 14:54













                        • 1





                          I just wanted to point out the difference between cp and scp as -r and -R are not the same. unix.stackexchange.com/questions/18712/…

                          – Tarun
                          Sep 23 '13 at 14:54








                        1




                        1





                        I just wanted to point out the difference between cp and scp as -r and -R are not the same. unix.stackexchange.com/questions/18712/…

                        – Tarun
                        Sep 23 '13 at 14:54






                        I just wanted to point out the difference between cp and scp as -r and -R are not the same. unix.stackexchange.com/questions/18712/…

                        – Tarun
                        Sep 23 '13 at 14:54












                        5














                        The best way is to use rsync over SSH



                        rsync -a -essh /source/ user@dest-server:/dest/

                        rsync -a -essh user@source-server:/source/ /dest/


                        My favorites options are -Pazvessh --delete :



                        • -a : archive mode (include a lot of default common options, including preserving symlinks)

                        • -z : compress

                        • -v : verbose : show files

                        • -P : show progess as files done/remaining files

                        • -e ssh : do rsync in ssh protocol

                        • --delete : delete files in the destination that are not anymore in the source





                        share|improve this answer























                        • All versions of rsync that I have used would use ssh by default, so -essh is unlikely to be needed. And the choice of command used to connect to the remote host is really unrelated to copying recursively.

                          – kasperd
                          Nov 5 '15 at 19:03















                        5














                        The best way is to use rsync over SSH



                        rsync -a -essh /source/ user@dest-server:/dest/

                        rsync -a -essh user@source-server:/source/ /dest/


                        My favorites options are -Pazvessh --delete :



                        • -a : archive mode (include a lot of default common options, including preserving symlinks)

                        • -z : compress

                        • -v : verbose : show files

                        • -P : show progess as files done/remaining files

                        • -e ssh : do rsync in ssh protocol

                        • --delete : delete files in the destination that are not anymore in the source





                        share|improve this answer























                        • All versions of rsync that I have used would use ssh by default, so -essh is unlikely to be needed. And the choice of command used to connect to the remote host is really unrelated to copying recursively.

                          – kasperd
                          Nov 5 '15 at 19:03













                        5












                        5








                        5







                        The best way is to use rsync over SSH



                        rsync -a -essh /source/ user@dest-server:/dest/

                        rsync -a -essh user@source-server:/source/ /dest/


                        My favorites options are -Pazvessh --delete :



                        • -a : archive mode (include a lot of default common options, including preserving symlinks)

                        • -z : compress

                        • -v : verbose : show files

                        • -P : show progess as files done/remaining files

                        • -e ssh : do rsync in ssh protocol

                        • --delete : delete files in the destination that are not anymore in the source





                        share|improve this answer













                        The best way is to use rsync over SSH



                        rsync -a -essh /source/ user@dest-server:/dest/

                        rsync -a -essh user@source-server:/source/ /dest/


                        My favorites options are -Pazvessh --delete :



                        • -a : archive mode (include a lot of default common options, including preserving symlinks)

                        • -z : compress

                        • -v : verbose : show files

                        • -P : show progess as files done/remaining files

                        • -e ssh : do rsync in ssh protocol

                        • --delete : delete files in the destination that are not anymore in the source






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Nov 5 '15 at 18:33









                        mickmick

                        57056




                        57056












                        • All versions of rsync that I have used would use ssh by default, so -essh is unlikely to be needed. And the choice of command used to connect to the remote host is really unrelated to copying recursively.

                          – kasperd
                          Nov 5 '15 at 19:03

















                        • All versions of rsync that I have used would use ssh by default, so -essh is unlikely to be needed. And the choice of command used to connect to the remote host is really unrelated to copying recursively.

                          – kasperd
                          Nov 5 '15 at 19:03
















                        All versions of rsync that I have used would use ssh by default, so -essh is unlikely to be needed. And the choice of command used to connect to the remote host is really unrelated to copying recursively.

                        – kasperd
                        Nov 5 '15 at 19:03





                        All versions of rsync that I have used would use ssh by default, so -essh is unlikely to be needed. And the choice of command used to connect to the remote host is really unrelated to copying recursively.

                        – kasperd
                        Nov 5 '15 at 19:03











                        4














                        After looking for the recursive copy flag, and successfully used it thanks to this post, I would like to post just a suggestion.



                        If the case is that you are copying (recursively) a directory. Maybe if the files are sent compressed you could save time in the transfer



                        What I did in the end was:



                        local$ tar -czvf local.tar.gz directory/
                        local$ scp local.tar.gz user@remote:/directory
                        ssh user@remote
                        remote$ tar -xzvf local.tar.gz


                        Hope this helps






                        share|improve this answer

























                        • the file extension should be either .tar.gz or .tgz since the file is a gzipped tar archive (since the -z flag is used).

                          – anthonybell
                          Mar 26 '18 at 22:07















                        4














                        After looking for the recursive copy flag, and successfully used it thanks to this post, I would like to post just a suggestion.



                        If the case is that you are copying (recursively) a directory. Maybe if the files are sent compressed you could save time in the transfer



                        What I did in the end was:



                        local$ tar -czvf local.tar.gz directory/
                        local$ scp local.tar.gz user@remote:/directory
                        ssh user@remote
                        remote$ tar -xzvf local.tar.gz


                        Hope this helps






                        share|improve this answer

























                        • the file extension should be either .tar.gz or .tgz since the file is a gzipped tar archive (since the -z flag is used).

                          – anthonybell
                          Mar 26 '18 at 22:07













                        4












                        4








                        4







                        After looking for the recursive copy flag, and successfully used it thanks to this post, I would like to post just a suggestion.



                        If the case is that you are copying (recursively) a directory. Maybe if the files are sent compressed you could save time in the transfer



                        What I did in the end was:



                        local$ tar -czvf local.tar.gz directory/
                        local$ scp local.tar.gz user@remote:/directory
                        ssh user@remote
                        remote$ tar -xzvf local.tar.gz


                        Hope this helps






                        share|improve this answer















                        After looking for the recursive copy flag, and successfully used it thanks to this post, I would like to post just a suggestion.



                        If the case is that you are copying (recursively) a directory. Maybe if the files are sent compressed you could save time in the transfer



                        What I did in the end was:



                        local$ tar -czvf local.tar.gz directory/
                        local$ scp local.tar.gz user@remote:/directory
                        ssh user@remote
                        remote$ tar -xzvf local.tar.gz


                        Hope this helps







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Mar 26 '18 at 23:20

























                        answered Jun 6 '15 at 18:00









                        xyzxyz

                        1536




                        1536












                        • the file extension should be either .tar.gz or .tgz since the file is a gzipped tar archive (since the -z flag is used).

                          – anthonybell
                          Mar 26 '18 at 22:07

















                        • the file extension should be either .tar.gz or .tgz since the file is a gzipped tar archive (since the -z flag is used).

                          – anthonybell
                          Mar 26 '18 at 22:07
















                        the file extension should be either .tar.gz or .tgz since the file is a gzipped tar archive (since the -z flag is used).

                        – anthonybell
                        Mar 26 '18 at 22:07





                        the file extension should be either .tar.gz or .tgz since the file is a gzipped tar archive (since the -z flag is used).

                        – anthonybell
                        Mar 26 '18 at 22:07











                        2














                        You can recursively copy a directory into a compressed archive with this simple command:



                        ssh -p 22 user@address-to-copy-from.com 'cd /parent/directory && tar zcvf - directory_to_copy' > /destination/on/your/machine/archive_name.tgz


                        For example, to copy contents of /var/log from domain.com to ~/logs.tgz you run:



                        ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' > ~/logs.tgz


                        You can also extract files on target system by using pipes. This command will copy contents of /var/log at domain.com to ~/destination/log on your system:



                        ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' | tar xzf - -C ~/destination


                        Though to mirror a directory, you probably should use rsync...






                        share|improve this answer





























                          2














                          You can recursively copy a directory into a compressed archive with this simple command:



                          ssh -p 22 user@address-to-copy-from.com 'cd /parent/directory && tar zcvf - directory_to_copy' > /destination/on/your/machine/archive_name.tgz


                          For example, to copy contents of /var/log from domain.com to ~/logs.tgz you run:



                          ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' > ~/logs.tgz


                          You can also extract files on target system by using pipes. This command will copy contents of /var/log at domain.com to ~/destination/log on your system:



                          ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' | tar xzf - -C ~/destination


                          Though to mirror a directory, you probably should use rsync...






                          share|improve this answer



























                            2












                            2








                            2







                            You can recursively copy a directory into a compressed archive with this simple command:



                            ssh -p 22 user@address-to-copy-from.com 'cd /parent/directory && tar zcvf - directory_to_copy' > /destination/on/your/machine/archive_name.tgz


                            For example, to copy contents of /var/log from domain.com to ~/logs.tgz you run:



                            ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' > ~/logs.tgz


                            You can also extract files on target system by using pipes. This command will copy contents of /var/log at domain.com to ~/destination/log on your system:



                            ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' | tar xzf - -C ~/destination


                            Though to mirror a directory, you probably should use rsync...






                            share|improve this answer















                            You can recursively copy a directory into a compressed archive with this simple command:



                            ssh -p 22 user@address-to-copy-from.com 'cd /parent/directory && tar zcvf - directory_to_copy' > /destination/on/your/machine/archive_name.tgz


                            For example, to copy contents of /var/log from domain.com to ~/logs.tgz you run:



                            ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' > ~/logs.tgz


                            You can also extract files on target system by using pipes. This command will copy contents of /var/log at domain.com to ~/destination/log on your system:



                            ssh -p 22 user@domain.com 'cd /var && tar zcvf - log' | tar xzf - -C ~/destination


                            Though to mirror a directory, you probably should use rsync...







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jan 6 '16 at 7:34

























                            answered Jan 6 '16 at 7:20









                            AnubiozAnubioz

                            2,634920




                            2,634920





















                                1














                                If you prefer to pass the user's password as a parameter rather than inputting it interactively, you can use sshpass (sudo apt-get install -y sshpass).



                                Example:



                                sshpass -p 'remote_password' scp -rp /src/folder myremoteusername@122.10.12.123:/dest/folder





                                share|improve this answer



























                                  1














                                  If you prefer to pass the user's password as a parameter rather than inputting it interactively, you can use sshpass (sudo apt-get install -y sshpass).



                                  Example:



                                  sshpass -p 'remote_password' scp -rp /src/folder myremoteusername@122.10.12.123:/dest/folder





                                  share|improve this answer

























                                    1












                                    1








                                    1







                                    If you prefer to pass the user's password as a parameter rather than inputting it interactively, you can use sshpass (sudo apt-get install -y sshpass).



                                    Example:



                                    sshpass -p 'remote_password' scp -rp /src/folder myremoteusername@122.10.12.123:/dest/folder





                                    share|improve this answer













                                    If you prefer to pass the user's password as a parameter rather than inputting it interactively, you can use sshpass (sudo apt-get install -y sshpass).



                                    Example:



                                    sshpass -p 'remote_password' scp -rp /src/folder myremoteusername@122.10.12.123:/dest/folder






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jan 6 '16 at 6:49









                                    Franck DernoncourtFranck Dernoncourt

                                    457926




                                    457926





















                                        0














                                        You can use -r option with scp command to copy directories recursively on any system. If you need anything else refer scp command tutorial. -r option stands for recursive operation in most of the Linux commands.






                                        share|improve this answer























                                        • While true, the -r option has already been suggested years ago and is the accepted answer.

                                          – RalfFriedl
                                          Apr 22 at 16:05















                                        0














                                        You can use -r option with scp command to copy directories recursively on any system. If you need anything else refer scp command tutorial. -r option stands for recursive operation in most of the Linux commands.






                                        share|improve this answer























                                        • While true, the -r option has already been suggested years ago and is the accepted answer.

                                          – RalfFriedl
                                          Apr 22 at 16:05













                                        0












                                        0








                                        0







                                        You can use -r option with scp command to copy directories recursively on any system. If you need anything else refer scp command tutorial. -r option stands for recursive operation in most of the Linux commands.






                                        share|improve this answer













                                        You can use -r option with scp command to copy directories recursively on any system. If you need anything else refer scp command tutorial. -r option stands for recursive operation in most of the Linux commands.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Apr 22 at 14:00









                                        atthikatthik

                                        11




                                        11












                                        • While true, the -r option has already been suggested years ago and is the accepted answer.

                                          – RalfFriedl
                                          Apr 22 at 16:05

















                                        • While true, the -r option has already been suggested years ago and is the accepted answer.

                                          – RalfFriedl
                                          Apr 22 at 16:05
















                                        While true, the -r option has already been suggested years ago and is the accepted answer.

                                        – RalfFriedl
                                        Apr 22 at 16:05





                                        While true, the -r option has already been suggested years ago and is the accepted answer.

                                        – RalfFriedl
                                        Apr 22 at 16:05











                                        -3














                                        Another (likely better for repeated use) option is to use NFS - check out nfs-kernel-server and how to setup NFS shares.






                                        share|improve this answer


















                                        • 2





                                          This is complete nonsense. There are endless cases where you would use scp but NFS is not an option.

                                          – Sven
                                          Aug 11 '16 at 23:24















                                        -3














                                        Another (likely better for repeated use) option is to use NFS - check out nfs-kernel-server and how to setup NFS shares.






                                        share|improve this answer


















                                        • 2





                                          This is complete nonsense. There are endless cases where you would use scp but NFS is not an option.

                                          – Sven
                                          Aug 11 '16 at 23:24













                                        -3












                                        -3








                                        -3







                                        Another (likely better for repeated use) option is to use NFS - check out nfs-kernel-server and how to setup NFS shares.






                                        share|improve this answer













                                        Another (likely better for repeated use) option is to use NFS - check out nfs-kernel-server and how to setup NFS shares.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Aug 11 '16 at 22:08









                                        Andrei PokrovskyAndrei Pokrovsky

                                        971




                                        971







                                        • 2





                                          This is complete nonsense. There are endless cases where you would use scp but NFS is not an option.

                                          – Sven
                                          Aug 11 '16 at 23:24












                                        • 2





                                          This is complete nonsense. There are endless cases where you would use scp but NFS is not an option.

                                          – Sven
                                          Aug 11 '16 at 23:24







                                        2




                                        2





                                        This is complete nonsense. There are endless cases where you would use scp but NFS is not an option.

                                        – Sven
                                        Aug 11 '16 at 23:24





                                        This is complete nonsense. There are endless cases where you would use scp but NFS is not an option.

                                        – Sven
                                        Aug 11 '16 at 23:24

















                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Server Fault!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f264595%2fcan-scp-copy-directories-recursively%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

                                        Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

                                        Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020