Hi,
I'd do it with WWW::Mechanize. Use WWW::Mechanize::Shell to connect (after setting the proxy as http_proxy env. variable), authenticate and upload, then use script <filename> to generate a Perl script which does exactly what you did in the shell. Then build your application around it.
Regards,
svenXY