You can certainly apply -- in the sense that the circumstances you have described does not require the Portuguese consulate in London to reject an application from you.
The Schengen visa processing handbook gives this example:
However, an application may
be accepted from a person legally present – but not residing - in
the jurisdiction of the consulate where the application is submitted, if
he can justify why the
application could not be lodged at
a consulate in his place of residence. It is for the consulate
to appreciate whether the justification
presented by the applicant is acceptable.
A Chinese professor has travelled to
London to teach at a university summer
school. During her stay, her father, who lives in France, falls
seriously ill and in order to
travel to France the Chinese woman applies for a visa at the French consulate in London.
The French consulate in London should deal
with the application because it would be
excessive to require the person concerned to return
to her country of residence to apply for the
You will still have to convince the Portuguese that you should be given a visa -- in particular, that you intend to leave the Schengen area after your proposed visit -- and all other things being equal, being about to lose your right to stay in the UK will make this harder for you.
They are obliged to start with the suspicion that you're a prospective economic migrant, so you'll have to present good evidence that you'd want to go back to the UK and thence back to Ecuador rather than stay illegally in the Schengen area. Since whatever is there to draw you back towards Ecuador has not been strong enough to keep you from spending a year in the UK, and it won't be much of a pull for an economic migrant to have just a handful of weeks of remaining legal presence in the UK to return to, this will take better and more convincing evidence than in a more run-of-the-mill case.
On the other hand, having had an earlier Schengen visa (and, presumably, having used it in accordance with the rules) will to some measure count in your favor.
How much harder this is is impossible to quantify. You can only try and see if that will be enough. Just be aware that you have some automatic assumptions working against you and try to address those head-on in your application.
You can apply even before your current visa expires; the visa you apply for just cannot be valid concurrently with another Schengen visa.