Generally what you describe occurs via a compromised users password, which the badguys then use to upload the appended code via either FTP or SSH (usually FTP) via that stolen password. You may want to read this article:
Check your desktops for malware too, if they stole your password 99.99999% of the time it from your desktop/laptop/etc. via a trojan. Also, if you use any tools that save your passwords make sure you dont save them anymore unless you rebuild your desktops from known trusted sources (and even then, dont save your passwords).