in reply to recursive SFTP

If you happen to be working in a linux environment, you could approach this a bit differently by using the fuse kernel module with the lftpfs driver to let the OS manage the network connection (including the sftp protocol). Then the problem looks more like doing a recursive copy.

Fuse has also been ported to FreeBSD and OS X, but I don't know if the lftpfs driver works on those platforms.

Apropos of nothing, the lftpfs fuse driver is written in Perl.

See:
http://fuse.sourceforge.net/
http://lftpfs.sourceforge.net/
http://fuse4bsd.creo.hu/
http://code.google.com/p/macfuse/