That is controlled by the server and the client. For example, if you connect to a ftp server, it makes its initial request at port 21, then the server tells your client something like, "go to port 15342 for further info", and then they communicate at that port. The server can be told to run on a different port through its configuration, but that is just the initial contact port, then the server always spins it off to some other free port.
I don't think there is anyway to control what port is chosen. Certainly not from the client, and probably not from the server either.