scp or rsync analogue for cp -T (treat target as file)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












With cp I can:



$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q


How do I get same effect in one command with scp and/or rsync? I.e. When target is directory I want it to exit with non-zero exit code without actual file transfer. I don't want file s to be placed in directory q.



Of course, it can be checked separately. The question is how to do that in one single command. Particularly, for the sake of concurrency.







share|improve this question





















  • Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
    – kemotep
    Apr 19 at 18:08










  • @kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
    – George Sovetov
    Apr 19 at 18:17














up vote
1
down vote

favorite












With cp I can:



$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q


How do I get same effect in one command with scp and/or rsync? I.e. When target is directory I want it to exit with non-zero exit code without actual file transfer. I don't want file s to be placed in directory q.



Of course, it can be checked separately. The question is how to do that in one single command. Particularly, for the sake of concurrency.







share|improve this question





















  • Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
    – kemotep
    Apr 19 at 18:08










  • @kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
    – George Sovetov
    Apr 19 at 18:17












up vote
1
down vote

favorite









up vote
1
down vote

favorite











With cp I can:



$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q


How do I get same effect in one command with scp and/or rsync? I.e. When target is directory I want it to exit with non-zero exit code without actual file transfer. I don't want file s to be placed in directory q.



Of course, it can be checked separately. The question is how to do that in one single command. Particularly, for the sake of concurrency.







share|improve this question













With cp I can:



$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q


How do I get same effect in one command with scp and/or rsync? I.e. When target is directory I want it to exit with non-zero exit code without actual file transfer. I don't want file s to be placed in directory q.



Of course, it can be checked separately. The question is how to do that in one single command. Particularly, for the sake of concurrency.









share|improve this question












share|improve this question




share|improve this question








edited Apr 19 at 17:44
























asked Apr 19 at 17:25









George Sovetov

1064




1064











  • Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
    – kemotep
    Apr 19 at 18:08










  • @kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
    – George Sovetov
    Apr 19 at 18:17
















  • Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
    – kemotep
    Apr 19 at 18:08










  • @kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
    – George Sovetov
    Apr 19 at 18:17















Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
– kemotep
Apr 19 at 18:08




Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
– kemotep
Apr 19 at 18:08












@kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
– George Sovetov
Apr 19 at 18:17




@kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
– George Sovetov
Apr 19 at 18:17










2 Answers
2






active

oldest

votes

















up vote
0
down vote













This will abort if the remote directory in question exists:



if ! ssh user@host "[[ -d /path/to/directory ]]"; then
# do your scp or rsync
else
echo "Remote location is a directory. Aborting." 1&>2
exit 1
fi


If you want to make this into a one-liner, then:



ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>





share|improve this answer





















  • Currently, I'm doing similar check. I would be great if I had one command solution...
    – George Sovetov
    Apr 19 at 17:49

















up vote
0
down vote













As an option:



ssh remote-server 'cat > /tmp/asd' < /tmp/qwe


Not a parameter though.



Example:



$ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
bash: /tmp/oi: Is a directory
Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
Bytes per second: sent 60414.8, received 54356.2
1
$ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
Bytes per second: sent 62499.8, received 55084.5
0
$ ls -l /tmp/qwe,asd,oi
-rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
-rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe

/tmp/oi:
total 0





share|improve this answer





















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438785%2fscp-or-rsync-analogue-for-cp-t-treat-target-as-file%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    This will abort if the remote directory in question exists:



    if ! ssh user@host "[[ -d /path/to/directory ]]"; then
    # do your scp or rsync
    else
    echo "Remote location is a directory. Aborting." 1&>2
    exit 1
    fi


    If you want to make this into a one-liner, then:



    ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>





    share|improve this answer





















    • Currently, I'm doing similar check. I would be great if I had one command solution...
      – George Sovetov
      Apr 19 at 17:49














    up vote
    0
    down vote













    This will abort if the remote directory in question exists:



    if ! ssh user@host "[[ -d /path/to/directory ]]"; then
    # do your scp or rsync
    else
    echo "Remote location is a directory. Aborting." 1&>2
    exit 1
    fi


    If you want to make this into a one-liner, then:



    ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>





    share|improve this answer





















    • Currently, I'm doing similar check. I would be great if I had one command solution...
      – George Sovetov
      Apr 19 at 17:49












    up vote
    0
    down vote










    up vote
    0
    down vote









    This will abort if the remote directory in question exists:



    if ! ssh user@host "[[ -d /path/to/directory ]]"; then
    # do your scp or rsync
    else
    echo "Remote location is a directory. Aborting." 1&>2
    exit 1
    fi


    If you want to make this into a one-liner, then:



    ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>





    share|improve this answer













    This will abort if the remote directory in question exists:



    if ! ssh user@host "[[ -d /path/to/directory ]]"; then
    # do your scp or rsync
    else
    echo "Remote location is a directory. Aborting." 1&>2
    exit 1
    fi


    If you want to make this into a one-liner, then:



    ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>






    share|improve this answer













    share|improve this answer



    share|improve this answer











    answered Apr 19 at 17:47









    DopeGhoti

    40k54779




    40k54779











    • Currently, I'm doing similar check. I would be great if I had one command solution...
      – George Sovetov
      Apr 19 at 17:49
















    • Currently, I'm doing similar check. I would be great if I had one command solution...
      – George Sovetov
      Apr 19 at 17:49















    Currently, I'm doing similar check. I would be great if I had one command solution...
    – George Sovetov
    Apr 19 at 17:49




    Currently, I'm doing similar check. I would be great if I had one command solution...
    – George Sovetov
    Apr 19 at 17:49












    up vote
    0
    down vote













    As an option:



    ssh remote-server 'cat > /tmp/asd' < /tmp/qwe


    Not a parameter though.



    Example:



    $ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
    Authenticated to localhost ([::1]:22).
    bash: /tmp/oi: Is a directory
    Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
    Bytes per second: sent 60414.8, received 54356.2
    1
    $ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
    Authenticated to localhost ([::1]:22).
    Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
    Bytes per second: sent 62499.8, received 55084.5
    0
    $ ls -l /tmp/qwe,asd,oi
    -rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
    -rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe

    /tmp/oi:
    total 0





    share|improve this answer

























      up vote
      0
      down vote













      As an option:



      ssh remote-server 'cat > /tmp/asd' < /tmp/qwe


      Not a parameter though.



      Example:



      $ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
      Authenticated to localhost ([::1]:22).
      bash: /tmp/oi: Is a directory
      Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
      Bytes per second: sent 60414.8, received 54356.2
      1
      $ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
      Authenticated to localhost ([::1]:22).
      Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
      Bytes per second: sent 62499.8, received 55084.5
      0
      $ ls -l /tmp/qwe,asd,oi
      -rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
      -rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe

      /tmp/oi:
      total 0





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        As an option:



        ssh remote-server 'cat > /tmp/asd' < /tmp/qwe


        Not a parameter though.



        Example:



        $ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
        Authenticated to localhost ([::1]:22).
        bash: /tmp/oi: Is a directory
        Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
        Bytes per second: sent 60414.8, received 54356.2
        1
        $ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
        Authenticated to localhost ([::1]:22).
        Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
        Bytes per second: sent 62499.8, received 55084.5
        0
        $ ls -l /tmp/qwe,asd,oi
        -rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
        -rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe

        /tmp/oi:
        total 0





        share|improve this answer













        As an option:



        ssh remote-server 'cat > /tmp/asd' < /tmp/qwe


        Not a parameter though.



        Example:



        $ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
        Authenticated to localhost ([::1]:22).
        bash: /tmp/oi: Is a directory
        Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
        Bytes per second: sent 60414.8, received 54356.2
        1
        $ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
        Authenticated to localhost ([::1]:22).
        Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
        Bytes per second: sent 62499.8, received 55084.5
        0
        $ ls -l /tmp/qwe,asd,oi
        -rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
        -rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe

        /tmp/oi:
        total 0






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 19 at 18:22









        George Sovetov

        1064




        1064






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438785%2fscp-or-rsync-analogue-for-cp-t-treat-target-as-file%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay