Often the sharing goes commercial, and money changes hands. That's when people often get caught, because large sums of money are meant to extract large amounts of classified data. In some cases, there is an ethnic factor. Jewish Americans have been caught passing information to Israel, partly out of a desire to help preserve Israel in the face of danger. Recently, a Filipino-American analyst sold intelligence data to a former Philippine government official. Several Chinese-Americans have been caught in the last few years, passing data on to people in China and Taiwan.
Nevertheless, whatever the motive, after trial and conviction, the sentences are usually the same, no matter what the motive, or destination of the date.
While most Americans focus on the "threat" of espionage on behalf of countries believed hostile to the U.S., such as China, Cuba, Iran, or Russia, it appears that there is may be as much spying being done for friendly countries, such as Israel, the Philippines, Taiwan, Japan, and several European ones. This might be thought of as strange, but American intelligence agencies are often quite tight-fisted with information, and are not willing to share it even with countries that are quite close to the U.S. One of the few exceptions is Britain, and that is part of the "special relationship." As a result, there is a great deal of unofficial, freelance "sharing" of information by low level American military, police, intelligence, and other officials who think we're short-changing our friends.