I'm not quite sure how much information is wanted, so I'll try and start simple. If I start throwing around terms you don't know, ask. If you think I left something out, ask 'cause I probably did leave it out.
Ships need to declare their intentions to the Coast Guard at least
72 96 hours prior to arriving in coastal waters. (The port they go to can change once the CG has notice of arrival in waters.) Faxes and emails get this done much easier these days. If the ship has not been inspected recently or the Coasties feel like it, she'll be boarded and inspected, generally where the ship picks up her pilot. (Cargo manifests, bills of lading, ship store lists, crew lists and such are emailed to Customs and the agent days in advance.)
Pilots are locals with detailed knowledge of the harbor. They work for the ship, but the ship is liable for any damage a pilot might cause. In New York harbor they are required on large ships. There is often a second pilot who is on board to guide the tugs into the berth.
Often ships enter the harbor with too deep a draft (vertical distance between the waterline and the bottom of the keel) to reach their berth. They lighter in the harbor to a barge, sometimes all their cargo is lightered and they sail without tying up to land.
[Edited to make right, since I was wrong the first time.]