Presenting Test::SFTP

xsawyerx on 2009-01-07T16:16:42

On a project at $work I was counting heavily on Net::SFTP to upload to, download from or check files on servers. Unfortunately I got weird results here and there. I figured if I could only have a testing framework for Net::SFTP, I could use it instead of doing hackery around it. I could also write a testing suite based on it. Testing suites are one of the best tools available to a sysadmin.

Anyway, without further ado, I present you Test::SFTP 0.01!

Test::SFTP provides the following methods:

  • connect (internally-used method)
  • can_connect
  • cannot_connect
  • is_status
  • is_status_number
  • is_status_string
  • can_get
  • cannot_get
  • can_put
  • cannot_put
  • can_ls
  • cannot_ls
Also, it has the following attributes:
  • Net::SFTP attributes:
    • host
    • user
    • password
    • debug
    • warn
    • ssh_args
  • object
  • connected
  • auto_connect

A few highlights:
  • Allows direct object access through $t_sftp->object
  • Uses Moose!
  • Automatic connect when using methods that require connectivity
  • Allows pretty much all major Net::SFTP methods
  • Complete testing suite (unlike Net::SFTP *cough*) for all functions, bearing you set TEST_SFTP_RUN_TEST=1

Some more stuff I want to add:
  • Allow not to connect automatically - forget to write it in the first version
  • Support every Net::SFTP methods
  • Timeout option for connection
  • Support the remote path in can_get, cannot_get
  • Write an SSH server or something, to control the testing

Things will have to wait a bit with this, because I've gotten the crucial part I needed from it. I'll definitely keep it updated, but probably will take more than a few days to be updated with more stuff. :)

Enjoy.