Search code examples
linuxfilescp

how to use scp to copy files and not overwrite files in the distination with same name


I am writing an automated test script that will copy the files from the remote location and make changes to it before copying them to another remotely connected machine.I want to copy a file from a remote machine to my local machine. I am using scp. It was all good until I found out that I have another file in my local with the same name. I either have to change the name of the file in the source or in the destination every time I use scp. I want to avoid this overhead. Is there any hack to just copy the file with the name that we desire to? Like for example:

scp filename user@sysname:/path/ dest_filename

Solution

  • Based off of: https://en.wikipedia.org/wiki/Secure_copy#Function

    scp user@host:directory/SourceFile TargetFile
    

    Would copy the "SourceFile", say, from remote, to the local path "TargetFile".

    So you could in theory do:

    scp bob@remotecomputer:directory/LogonTime.txt /somelocalpath/LogonTime20181119.txt