Section 1. Whoever, not being a pilot or public officer, shall board or attempt to board a vessel arriving in the harbor of Boston, Salem, Fall River, New Bedford and Fairhaven or Gloucester, before such vessel has been made fast to the wharf, without the previous permission of the master or person having charge thereof or the previous written permission of its owners or agent, or whoever, without such leave and without authority of law, shall board a vessel in any of said harbors after having been forbidden so to do by a person having charge thereof at the time, or, having boarded such vessel, shall refuse or neglect to leave it when ordered so to do by the person having charge of it, shall forfeit not more than fifty dollars.