I love using WinSCP for so many reasons. One of the many really cool features of WinSCP is the ability to add custom commands. In this article, I will describe how to integrate WinMerge into WinSCP to compare a local version of a file to a remote version.
When comparing online and offline source code files, the process is typically to download the online file over FTP or SCP using WinSCP and then compare that to a local version of the file using some file comparison tool or eye-balling the two files in a code editor by flipping back and forth. Doing this once in a while isn't too inconvenient but if you need to compare online and offline files regularly or compare very large files, this process can quickly become a real pain.
How to integrate WinMerge into WinSCP
- Launch WinSCP and login to an FTP site. Like most of WinSCP's features, you have to be logged in to see its main user interface.
- Click Options > Preferences in the WinSCP menu.
- In the left pane of the Preferences dialogue box, click Commands.
- Click the Add button.
- For the description field, simply enter WinMerge. This is what will appear in the WinSCP toolbar so keep it short.
- In the custom command field, enter one of the following depending on your version of Windows:
- 32-bit Windows: "C:\Program Files (x86)\WinMerge\WinMergeU.exe" /dr "!@:!/" "!^!" "!"
- 64-bit Windows: "C:\Program Files\WinMerge\WinMergeU.exe" /dr "!@:!/" "!^!" "!"
- Make sure the Local command radio button is selected and Apply to directories is checked. All the other checkboxes should be unchecked.
- You can optionally assign a keyboard shortcut.
- Click OK and then OK again.
Next, make the Custom Command Bar visible:
- Right click on any of icons in the toolbar.
- Select Custom Command Buttons.
Now you can compare your online and offline text source code using the new WinMerge button in the toolbar:
As you may have noticed, I use this technique to create additional useful toolbar command to test my PHP code for syntax errors. You can do this with almost any tool that accepts command line parameters.
A few notes
First, you may notice that the WinMerge button is greyed out at times. This will happen because WinMerge doesn't know what you want to compare until you have selected a file on both the local and remove sides.
You can use this to compare multiple files at the same time. WinSCP will popup a WinMerge window for each pair to be compared. Note however that WinSCP will occasionally get mixed up and start comparing the wrong pair of files together. In that case, you will need to revert back to doing comparisons one file at a time.
Finally, a productivity tip: To make using WinMerge a little more convenient, you can also add the following command line switches just before the "/dr" so that it will end up looking like "/e /x /u /dr". The rest of the command line should remain the same.
- /e : Enables you to close WinMerge with a single Esc key press.
- /x : Closes WinMerge (after displaying an information dialog) when you start a comparison of identical files.
- /u : Prevents WinMerge from adding either path (left or right) to the Most Recently Used (MRU) list.
WinMerge has many other command line switches. See the WinMerge documentation for more information.
Best regards,
Michael Milette
February 25, 2014 at 2:58 PM
Thanks for this!
BTW, your blog post turned the quotes in the command text into smart quotes … I had a bear of a time until I realized that!
February 25, 2014 at 4:09 PM
Hi Greg, sorry about that. Thanks for taking the time to let me know. The problem has been fixed site-wide.
April 2, 2014 at 8:03 AM
thanks…
April 13, 2014 at 5:12 AM
Oh great. I never thought this is possible with WinSCP. I’m always using Git to compare offline and online source code. Thanks for sharing! 😀
September 22, 2014 at 2:27 PM
Will these commands work for a folder compare/multiple files in WinMerge? I would like to be able to select multiple files (or a folder) and have that come up in a compare list rather than having each file compared one at a time.
Thanks for the great article!
September 22, 2014 at 10:56 PM
Hi Ken, thanks for the great question. It will indeed! However, you will have to close WinMerge completely after each file before it will open the next. You also won’t be able to abort the process so, if you select 2 local and 2 remote files, you won’t be able to abort the process after the first set of files. Same goes for folders. I am not sure how multiple sets of files/folders are matched up so there may be cases where it compares the wrong set of files however I haven’t been able to produce that result unless I was selecting different local and remote files.
Note that comparison of folders is much slower as it has to download all the files and folders in the folder.
Thanks for the words of appreciation for the article. I really enjoy hearing from visitors.
Best regards,
Michael Milette
August 20, 2015 at 1:46 AM
Thank you for very useful post.
February 21, 2016 at 12:38 PM
Thanks for this very informative and usefule post! one thing worth mentioning: in the command window it’s most important to check the “local command” radio button. I got a couple of annoying error messages before I realized it’s actually checked in the screenshot you have provided. 🙂
February 26, 2016 at 5:40 PM
Thanks for the feedback Kernmt! I really appreciate your time in sending me your comment. I’ve applied the change that you recommended to the article. Thanks again! 🙂
March 28, 2016 at 3:07 PM
How about comparing two remote files? How can that be made possible?
April 4, 2016 at 5:27 AM
Hi Ankit,
That’s a great question. You certainly can. Simply redo the above steps with a couple of differences.
“C:\Program Files (x86)\WinMerge\WinMergeU.exe” !&
It works quite well for comparing 2 selected Remote files.
Limitation: It does NOT work for comparing 2 directories and doesn’t automatically upload files if you save changes.
Best regards,
Michael
October 27, 2016 at 7:23 AM
Good explanation.
November 16, 2016 at 4:08 PM
Thank you Maciek!
December 9, 2016 at 5:59 AM
You have saved my life!
June 20, 2017 at 11:04 PM
Thanks.. so useful.
September 21, 2017 at 4:30 PM
Hi, is this still working with the instructions above? Instead of comparing files, WinSCP is just downloading them when I try this.
October 26, 2017 at 1:38 PM
Absolutely! I just did a new installation a few weeks ago for a colleague.
September 6, 2018 at 11:00 PM
Thank you for this great tutorial.
November 25, 2018 at 8:07 AM
I guess you’ve meant:
32-bit Windows: “C:\Program Files (x86)\WinMerge\WinMergeU.exe” /dr “!@:!/” “!^!” “!”
64-bit Windows: “C:\Program Files\WinMerge\WinMergeU.exe” /dr “!@:!/” “!^!” “!”
November 25, 2018 at 2:07 PM
Hi István, good catch! Thank you so much for pointing that out. I have updated the article. Best regards, Michael
March 6, 2019 at 9:27 AM
I am getting the below error when i click on WinMerge. Can somebody help?
Windows cannot find “C:\Program Files (x86)\WinMerge\WinMergeU.exe”. Make sure you typed the name correctly, and then try again
March 19, 2019 at 10:26 PM
Hi Sk,
1. Make sure you installed WinMerge.
2. If you installed the 64 bit version, you will need to change that to C:\Program Files\WinMerge\WinMergeU.exe or wherever you installed it.
Hope this helps.
Best regards,
Michael
June 9, 2020 at 6:39 AM
I don’t know if you are still reading your comments, but I hope so cause you are a legend. This is exactly what I needed. Thanks a heap.
July 22, 2020 at 8:01 AM
Hi Michael,
Thanks for your great info!.
“C:\Program Files\WinMerge\WinMergeU.exe” /e /x /u /r /dr “!@:!/” “!^!” “!”
I used above command line option. I can copy from local to remote server for only those different files but I can not copy files/folders which is available only in local machine and not yet upload in remote server.
In this case if I want to copy those new files and folders from local machine to remoter server is there command line option need to add.
Please help us we need this urgently.
BR,
Kabo
December 29, 2020 at 5:35 AM
Hi Kabo, You should be able to do that using functionality built into WinSCP. Just have it compare the directory listings. It will show you all of the files that exist in one place and not the other.
June 14, 2022 at 8:58 PM
I’m way late for this article, but I’m still an avid user of WinSCP. I’m not quite sure what you’re accomplishing with WinMerge here – you talk about source code – in the context of SFTP transfer? I’m not sure what you’re doing, sorry for being dumb.
I’m after a mechanism that I can use pretty easily in a WinSCP .NET scripting setting to help validate that a given uploaded file and its remote counterpart are the same size, because I’m encountering instances of files failing to upload properly, or incompletely, necessitating re-work.
January 22, 2023 at 3:22 PM
Hi Daniel,
The purpose is to be able to compare a local file to the version online so that you can see the differences.
Hope that helps. Regards,
Michael