note 104267 added to function.ssh2-scp-recv
| From: | tomatitneodotcom at osu1 dot php dot net | Date: | Sat, 04 Jun 2011 19:40:37 +0000 |
| Subject: | note 104267 added to function.ssh2-scp-recv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180259@lists.php.net to get a copy of this message | ||
This program uses find to locate files on a remote system and scp receive them. I used find for its
many built in options.
<?php
// HOW MANY MINUTES OLD SHOULD THE FILE BE?
$file_age = 1;
// DEFINE THE LOCAL DIRECTORY (BE SURE TO USE TRAILING BACKSLASH!)
$directory_local = "/usr/home/user/";
// DEFINE THE REMOTE DIRECTORY (BE SURE TO USE TRAILING BACKSLASH!)
$directory_remote = "/usr/home/user/dropoff/";
// SSH CONNECTION INFO
$connection = ssh2_connect('ip_address/hostname', 22);
ssh2_auth_password($connection, 'user_name', 'password');
// EXECUTE THE COMMAND
$stream = ssh2_exec($connection, "find $directory_remote* -mmin +$file_age");
stream_set_blocking($stream, true);
// GET AN ARRAY OF THE OUTPUT
$arr = explode("\n", stream_get_contents($stream));
// DELETE EMPTY ELEMENTS
foreach ($arr as $value){
if ($value != ''){
$filename = str_replace($directory_remote, '', $value);
if (ssh2_scp_recv($connection, $value, $directory_local . $filename) != FALSE){
print "SCPd $value > $directory_local$filename\n";
} else {
print "Error SCPing: $value > $directory_local$filename\n";
}
}
}
fclose($stream);
?>
----
Server IP: 192.41.42.26
Probable Submitter: 206.123.123.220
----
Manual Page -- http://www.php.net/manual/en/function.ssh2-scp-recv.php
Edit -- https://master.php.net/note/edit/104267
Del: integrated -- https://master.php.net/note/delete/104267/integrated
Del: useless -- https://master.php.net/note/delete/104267/useless
Del: bad code -- https://master.php.net/note/delete/104267/bad+code
Del: spam -- https://master.php.net/note/delete/104267/spam
Del: non-english -- https://master.php.net/note/delete/104267/non-english
Del: in docs -- https://master.php.net/note/delete/104267/in+docs
Del: other reasons-- https://master.php.net/note/delete/104267
Reject -- https://master.php.net/note/reject/104267
Search -- https://master.php.net/manage/user-notes.php