Should not be problem. SQLyog works with MySQL versions from 3.23.x. Operating systems don't matter at all.
With SQLyog just open a connection to each server. From the connection to the 4.0 server right-click the database and select 'Copy database to other host/database'. Create the database to import to of 5.1 in advance. Note that 5.1 has a 'default character set' setting on the database level (4.0 only has on the server level). Choose the one that matches the encoding of you data (what will most likely be 'latin1' as 4.0 did not have utf8 or other unicode options)
If you have more database on the server you repeat the step for each database. Or simply dump/export and import.