in reply to Reading a Directory on another server
Your code, as presented, should work, so long as the $dir in question can be accessed from your shell.