views:

41

answers:

3

Hi,

I've been told that this is possible to do with PHP. I have my website and there is a selection box. I would like the options to be populated from the contents of a folder on an sftp server. Then upon click I would like to get the associated files and move them to my local machine. Are there any good tutorials on how to do this? I'm having trouble finding one.

Thanks

+1  A: 

This is the way:

http://stackoverflow.com/questions/717854/sftp-from-within-php

use cURL from PHP to query the remove SFTP server, for both listing and file retrieval.

Manual for php is here. You don't need any SSH scripts (which by the way is usually strictly forbidden on most shared hosting environment), if your sFTP server is publicly available. Curl will do everything for you.

Palantir
sftp isn't supported. curl sftp://user@host:22curl: (1) Unsupported protocol: sftp
msandbot
i'm trying to get the IT guy to update curl, ssh2 also looks useful. Wish i had root access. I tried exec('ssh blah blah') and that didn't work. also tried exec('perl sample.pl') where sample.pl just has `ssh blah blah blah` I don't think that it even ran.
msandbot
all functions like exec(), system(), etc. are always restricted, and it's really a hard task to have them enabled by the IT departments, as they open the way to potentially deadly vulnerabilities. If you can get your curl to work that'll be the best solution!
Palantir
+1  A: 

You can use exec method http://php.net/manual/en/function.exec.php

<?php
echo exec('ssh -help');
?>
SageNS
A: 

in the selection box you can list the files with:

   if (is_dir($dir)) {
        if ($fh = opendir($dir)) {
            while (($file = readdir($fh)) !== false) {
                if($file != "." && $file != "..") 
                    $files[] = $file;               
            }
            closedir($fh);
        }
    }

to transfer the files from one to another host you can use php exec and scp:

exec('scp host1:/path/to/oldfile host2:/path/to/newfile');
Oliver
he's trying to get the list from a remote server, while these functions will work on local server only
Palantir
oh, you're right the first one only works local. he could but this php code on the sftp server though ;) the second code should be applicable
Oliver