Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* the host name or ip to download from */
- $host = '192.168.1.2';
- /* the absolute path on the host name */
- $abspath = '/full/path/to/download';
- /* username for host */
- $user = 'cosmo';
- /* password for user on host */
- $pass = 'cosmo';
- /* trg file*/
- $trg = 'test.dat';
- /* get curl instance */
- $curl = curl_init();
- /* set url of file to download */
- $url = 'scp://' . $host . ':' . $abspath;
- curl_setopt($curl, CURLOPT_URL, $url);
- /* set credentials */
- curl_setopt($curl, CURLOPT_USERPWD, $user . ':' . $pass);
- /* set target file */
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- $fh = fopen($trg, 'w') or die('failed to open ' . $trg . ' for writing!');
- curl_setopt($curl, CURLOPT_FILE, $fh);
- /* start */
- echo "<p>Output of curl_exec</p><pre>";
- curl_exec($curl) or die(curl_error($curl));
- /* close the curl instance */
- echo "</pre>";
- curl_close($curl);
- fclose($fh);
- echo "<p>File should now be successfully downloaded from $url to $trg:</p>";
- echo '<pre>' . file_get_contents($trg) . '</pre>';
- ?>
Add Comment
Please, Sign In to add comment