What the basic problem here is that there is a protection again non-human input. TTY ensures that the action is performed from keyboard actions, and not from another program. Now there is a way around this.
If you have access to the sodeors file you can deal with this. It is not really recommended but here goes, this is really a way that works.
You open the file /etc/sudoers
and you find the following line:
Defaults:myusername !requiretty
This tells the the system that the user myusername
can perform non-keyboard actions. Now you can work with all your files using the sudo command.
Best is to try to avoid this.