Or at least a goal of turning one of them into Soviet allies? Was gaining a foothold in the Indian Ocean or Persian Gulf ever a long-term goal for the USSR?
Thanks.
This is a pretty hotly debated point, especially in relation to the USSR intervention in Afghanistan. However, recent research, especially investigations into old Politburo minutes, indicates sending troops into Afghanistan en masse (excluding decades of past advisor and technical assistance) was to prop up a faltering friendly regime located close to a staunch American ally (Iran) instead of a grandiose plan for warm water ports in the Persian Gulf. I recommend "A Long Goodbye" by Kalinovsky for more into the Soviet decision making process. Just a piece of the answer but I hope its a start!
The goals of the Soviet Union after World War II were rather... ambiguous, to say the least.
I don't know about Pakistan but maybe I could lighten you up about Iran. Rezā Shāh himself was very fond of the nazi regime (especially Hitler) and thought about siding with them (or at least that is what the allies claimed) so they invaded Iran, by that I mean the British and the Soviets. The Soviets were in charge of East Azerbaijan - the predominantly Azerbaijani/Kurdish area of Iran. They held that territory because it was de facto part of the Persian Corridor and it was the place where some of the British and American aid to the Soviet Union got through. During the time the soviets were there they left their mark by funding the communist party of Iran and overstaying their welcome in the occupied part of Iran (they held on to it until 1946), but they eventually moved out due to pressure from the UN (and some millitary pressure from Iran).
If you look at the soviet foreign policy as a whole you'll see that they were rather opportunistic and instead of outright conquest they perferred to overthrow governments and let the "revolution spread by itself", that was their plan with Iran too, in the crisis of 1946 the soviets weren't directly involved in the fighting, they just supported their puppet state, still, if Iran would have fallen to communism I doubt they would have been incorporated into the Soviet Union, the most likely scenario would be them serving as a satelite state, like all the other eastern block countries.
The Soviets tried to foster the Jangali party and influence the northern provinces of Iran, and move forward from there. For a brief period of time, the province of Gilan broke away and formed a Soviet republic before being subsumed back into Iran. cf. Cosroe Chaqueri, "The Soviet Socialist Republic of Iran, 1920-1921." ISBN 0-8229-3792-1
After this, the Soviets still influenced the Tudeh (Communist) party. It should be noted that the Tudeh party was the one backing Prime Minister Mossadegh's coup d'etat. The CIA's reinstallation of the Shah in 1953 could be interpreted as a proxy move in the overall Cold War strategy of containment.
A good example of this sort of thing would be the Baloch of Eastern Iran/Western Pakistan. They were briefly independent in historical times, before being subsumed into the politics of the Great Game and being divided into four pieces: three administered by British India, and one by the Persian Empire.
Their independence was seen as a matter of opportunity for the Soviets, who in pre-Revolution Iran, fomented no small amount of insurrection in the area in hopes of destabilizing the area, gaining a puppet state, and more importantly - a warm water port.
The revolution flipped the calculus a bit. Baloch leaders fell more in line with the Iranian government, after being promised by the Ayatollah that reforms would come to the region, and that the area would be fully brought into the Iranian socioeconomic sphere. Now, of course, we know that that never happened, and that this has caused no small amount of Baloch resentment, but that's another story.
Sources:
Harrison, Selig S. "Baluch Nationalism and Superpower Rivalry." < http://www.jstor.org/stable/2538424>.
Taheri, Ahmad Reza. "Baloch Insurgency and Challenges to the Islamic Republic of Iran" http://www.artaheri.org/files/article%202.pdf
I can speak to the ambitions of the Russian Empire, which may or may not shed light on Soviet priorities. However, as /u/duck_with_a_fez pointed out, actions in Afghanistan may have been more targeted at propping up friendly regimes than securing port access.
Throughout the 19th century, the Russian Empire and United Kingdom played out a series of diplomatic games and miniature conflicts in order to block the other's influence in Central Asia. The British very much feared Russian access to the sea as it would threaten their naval dominance of the sphere, as well as their possessions in India. Russian advances through Persia or Central Asian countries were seen as threats to their empire's crown jewel. Russia, meanwhile, sought to build a strong buffer zone to protect its "soft underbelly." Threats to India, in reality, were possibly trumped up by Russophobic officials working for the crown such as Lord Curzon. While to Brits the threat seemed real, Russian armies could probably not march over such a distance and mount a powerful enough attack through the Khyber pass, or over Iran, after traveling such a great distance through their own less-understood territories to their south.
Related to Iran specifically, in August 1907 the two countries divided it (while acknowledging its sovereignty) into to spheres of influence: with each protecting the half it was concerned could lead to the undoing of its territory. The Soviet Union did away with this agreement, reigniting British fears once again.
In the Soviet period, access to the ocean became less of a priority, possibly because it was ruled impossible as the Soviets tried to consolidate power in territory they already controlled (first through conquering exhibitions in Central Asia, then in the land they kept after World War II). They were disinclined to exert influence on India, as Jawaharlal Nehru was nominally a non-aligned socialist and desired friendship, but their position didn't really allow them to manipulate him in any way. Meanwhile, Iran came under the protection of the United States, which carried far greater consequences than intervention would have in the 19th century.
In short, it was probably mulled over by Russian imperial leaders, though they never did more than wage a diplomatic game over the territory. The opportunity simply wasn't there. Soviets were even less inclined to consider the idea, focusing more on just keeping Afghanistan in check.
Main source: The Great Game, by Peter Hopkirk
Also consulted: Gandhi and Churchill, by Arthur Herman
You ask a very interesting question. I am not a historian but I can give you an answer from the other side.
A Pakistani (Haqqani) wrote a very interesting book called Magnificent Delusions and he talks extensively about the relationships between Pakistan, Middle East nations, USSR and USA during the time of Joseph Stalin (basically the time of the birth of Pakistan).
He said that Pakistan was so busy trying to get on USA and Middle East nations good side that they actually went out of their way to not have high level meetings with USSR. Then when Pakistan was failing at getting the attention of USA and Middle East nations they spread a rumor that the leadership was going to meet with Joseph Stalin. That got the attention of the USA and they were able to get high level meetings with American leadership.