Search code examples
sshdiffbeyondcompare

Beyond compare remote with local file


I want to compare two text files one on remote the other local. With diff I would do that with

ssh user@login "cat myfile.txt" | diff - local.txt

Is there a way to perform the same comparison using Beyond Compare? If I do

ssh user@login "cat myfile.txt" | bcompare - local.txt

I get only the local file displayed.


Solution

  • One neat trick that I use in such cases is to use sshfs to make the remote directory appear as a local one to beyond compare:

    sshfs user@host:/opt/data /tmp/transfer
    

    Then you can use any diffing tool to compare your local data with the remote one via diff -Nur /local/data/dir /tmp/transfer or with beyond compare as usual and you can copy files back and forth as needed.

    Note, you might need to install sshfs via your package manager, e.g. on Debian/Ubuntu via apt-get install sshfs

    Possible options:

    • -o PubkeyAuthentication=no: If you need password authentication, but ssh first tries too many private key authenticaitions, not needed if you use private key auth for this server or no private key auth at all
    • -o sshfs_debug: Print out more information if authentication/connection fails
    • -o idmap=user: Use the idmap=user option to translate the UID of the connecting user to the remote user
    • -o gid=1000: uid, gid - set reported ownership of files to given values; uid is the numeric user ID of your user, gid is the numeric group ID of your user.
    • -o nomap=error: Fail if user mapping cannot be done

    See https://wiki.archlinux.org/index.php/SSHFS for more details.