The causes behind the external hard drive keep connecting issue are various, the disk may be put to sleep, the connection is defective, there are software bugs on your Mac, the external hard drive is corrupted, etc.
When the external hard drive keeps disconnecting on Mac, sudden power outages and improper ejection may damage the drive and corrupt the drive. Therefore, it is necessary to back up the drive with Time Machine and other methods, if any data loss, try data recovery software such as iBoysoft Data Recovery for Mac to recover it ASAP!
There are some proven methods you can try to fix external hard drive keeps disconnecting on Mac:
Connect the external hard drive directly to the Mac instead of the USB hub. According to your description, neither using the 7-port USB hub nor the 4-port USB hub can establish a stable connection. Perhaps, both two hubs are defective.
Change to another working USB port and cable. In addition to the hub, the port and cable could also be the culprit of the connection issue. Make sure the port and cable used to connect the external hard drive are not dead.
Disconnect unnecessary peripherals. If you have connected a number of accessories to Mac, one problematic device among them could be the culprit to making the external hard drive keeps connecting.
Check the sleep settings for external hard drive. Go to Apple menu > System Preferences > Battery. Disable the "Put hard disks to sleep when possible" option.
Restart your Mac. This could remove some temporary system glitches resulting in the external hard drive keeping disconnecting on Mac.
Repair or reformat the drive. Run First Aid in Disk Utility to check and repair the disk errors on the external hard drive. If it doesn't work, you can try to reformat the external disk on Mac. But you should back up the drive to avoid data loss.