Retrieving files from print queue

Hi,

wonder if anyone can help me out with this. I'm trying to retrieve files from a print queue on a remote server i.e. get files before they are printed. I'll be using perl to do this. I've written out some pseudocode below:

Telnet to print server
for ever (endless loop)
pause 1 second
run lpq command
parse output from lpq command
if there are any files in print queue
get list of files (how do we do this ????????)
for every file in print queue
ftp file to 'our' server
endfor
endif
endfor

Basically I cannot write any code on the remote server to do this I have to do it all using my own script on 'our' server. Does anyone know how I can actually retrieve the files from the print queue?

Any help would be much appreciated. Thanks.