本文整理汇总了PHP中ssh2_sftp_rename函数的典型用法代码示例。如果您正苦于以下问题:PHP ssh2_sftp_rename函数的具体用法?PHP ssh2_sftp_rename怎么用?PHP ssh2_sftp_rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ssh2_sftp_rename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_files
protected function get_files()
{
$server = $this->config->config_data['common']['host'];
$user = $this->config->config_data['common']['user'];
$password = $this->config->config_data['common']['password'];
$directory_remote = rtrim($this->config->config_data['import']['remote_basedir'], '/');
$directory_local = rtrim($this->config->config_data['import']['local_path'], '/');
$port = 22;
if (!function_exists("ssh2_connect")) {
die("function ssh2_connect doesn't exist");
}
if (!($connection = ssh2_connect($server, $port))) {
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if (!ssh2_auth_password($connection, $user, $password)) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...<br/>";
// Enter "sftp" mode
$sftp = @ssh2_sftp($connection);
// Scan directory
$files = array();
echo "Scanning {$directory_remote}<br/>";
$dir = "ssh2.sftp://{$sftp}{$directory_remote}";
$handle = opendir($dir);
while (false !== ($file = readdir($handle))) {
if (is_dir($file)) {
echo "Directory: {$file}<br/>";
continue;
}
/* if ($this->debug)
{
$size = filesize("ssh2.sftp://$sftp$directory_remote/$file");
echo "File $file Size: $size<br/>";
$stream = @fopen("ssh2.sftp://$sftp$directory_remote/$file", 'r');
$contents = fread($stream, filesize("ssh2.sftp://$sftp$directory_remote/$file"));
@fclose($stream);
echo "CONTENTS: $contents<br/><br/>";
}
*/
$files[] = $file;
}
if ($this->debug) {
_debug_array($files);
} else {
foreach ($files as $file_name) {
if (stripos($file_name, 'Px205') === 0) {
// _debug_array($file_name);
$file_remote = "{$directory_remote}/{$file_name}";
$file_local = "{$directory_local}/{$file_name}";
$stream = fopen("ssh2.sftp://{$sftp}{$file_remote}", 'r');
$contents = fread($stream, filesize("ssh2.sftp://{$sftp}{$file_remote}"));
fclose($stream);
$fp = fopen($file_local, "wb");
fwrite($fp, $contents);
if (fclose($fp)) {
echo "File remote: {$file_remote} was copied to local: {$file_local}<br/>";
if (ssh2_sftp_unlink($sftp, "{$directory_remote}/archive/{$file_name}")) {
echo "Deleted duplicate File remote: {$directory_remote}/archive/{$file_name}<br/>";
}
if (ssh2_sftp_rename($sftp, $file_remote, "{$directory_remote}/archive/{$file_name}")) {
echo "File remote: {$file_remote} was moved to remote: {$directory_remote}/archive/{$file_name}<br/>";
} else {
echo "ERROR! File remote: {$file_remote} failed to move to remote: {$directory_remote}/archive/{$file_name}<br/>";
if (unlink($file_local)) {
echo "Lokal file was deleted: {$file_local}<br/>";
}
}
}
}
}
}
}
}
}
示例2: rename
/**
* Renames a remote file
*
* @param string $from The current file that is being renamed
* @param string $to The new file name that replaces from
*
* @return Boolean TRUE on success, or FALSE on failure
*/
public function rename($from, $to)
{
return ssh2_sftp_rename($this->getResource(), $from, $to);
}
示例3: sftpRename
/**
* Facade for ssh2_sftp_rename.
*
* @param resource $resource The sftp resource to use.
* @param string $source_path The remote source path.
* @param string $dest_path The remote destination path.
*
* @return boolean True on success.
*/
public function sftpRename($resource, $source_path, $dest_path)
{
return ssh2_sftp_rename($resource, $source_path, $dest_path);
}
示例4: downloadOrders
/**
* Download order files from tb server
* @return Array of String contain filename that available on tb out folder
*/
public function downloadOrders()
{
use_class('jng_sp_download');
$class_jd = new jng_sp_download();
$result = false;
$target_dir = TRADEBYTE_FTP_OUT_PATH;
$local_dir = TRADEBYTE_DOWNLOAD_ORDERS_PATH;
$dir_handle = $this->openDir($target_dir);
$jng_sp_id = 0;
//ALL DOWNLOADED ORDERS VIA TRADEBYTE WE USE 0 AS jng_sp_id "ONLY" ON TABLE jng_sp_download
$download_status_to_generate = 'R';
while (($file = readdir($dir_handle)) !== false) {
if ($file != '.' && $file != '..') {
$downloaded_file = $this->downloadFile($target_dir . $file, $local_dir . $file);
if ($downloaded_file !== false && $downloaded_file != -1) {
$files[] = $downloaded_file;
$class_jd->addDownload($jng_sp_id, 'ORDERS', basename($downloaded_file), $download_status_to_generate);
$order_done_filename = TRADEBYTE_FTP_ARCHIVE_PATH . $this->getFilePrefixDone() . $file;
ssh2_sftp_rename($this->sftp, $target_dir . $file, $order_done_filename);
}
}
}
if (is_array($files) && count($files) > 0) {
$result = $files;
}
return $result;
}
示例5: rename
/**
* Remote rename.
*
* @param string $from
* @param string $to
*
* @return bool
*/
public function rename($from, $to)
{
ssh2_sftp_rename($this->resource, $from, $to);
}
示例6: mv
/**
* Rename file in remote server
*/
public function mv($remoteFile, $newName)
{
$from = $this->_getFilename($remoteFile);
$to = $this->_getFilename($newName);
if (!ssh2_sftp_rename($this->_getSftp(), $from, $to)) {
throw new \Exception("Could not rename file '{$from}' as '{$to}'");
}
}
示例7: move
/**
* Moves a file through the backend.
*
* @param string $path The path of the original file.
* @param string $name The name of the original file.
* @param string $dest The destination file name.
* @param boolean $autocreate Auto-create the directory if it doesn't
* exist?
*
* @throws Horde_Vfs_Exception
*/
public function move($path, $name, $dest, $autocreate = false)
{
$orig = $this->_getPath($path, $name);
if (preg_match('|^' . preg_quote($orig) . '/?$|', $dest)) {
throw new Horde_Vfs_Exception('Cannot move file(s) - destination is within source.');
}
$this->_connect();
if ($autocreate) {
$this->autocreatePath($dest);
}
foreach ($this->listFolder($dest, null, true) as $file) {
if ($file['name'] == $name) {
throw new Horde_Vfs_Exception(sprintf('%s already exists.', $this->_getPath($dest, $name)));
}
}
if (!@ssh2_sftp_rename($this->_sftp, $orig, $this->_getPath($dest, $name))) {
throw new Horde_Vfs_Exception(sprintf('Failed to move to "%s".', $this->_getPath($dest, $name)));
}
}
示例8: doMove
/**
* @see Filesystem::doMove
*/
protected function doMove($source, $destination)
{
wfSuppressWarnings();
$ssh2_sftp_rename = ssh2_sftp_rename($this->connection, $source, $destination);
wfRestoreWarnings();
return $ssh2_sftp_rename;
}
示例9: moveFileInternal
/**
* @inheritdoc
*/
public function moveFileInternal($srcFile, $destFile)
{
$srcFullFileName = $this->composeFullFileNameByReference($srcFile);
$destFullFileName = $this->composeFullFileNameByReference($destFile);
$this->createDirectory(dirname($destFullFileName));
$result = ssh2_sftp_rename($this->getStorage()->getSftp(), $srcFullFileName, $destFullFileName);
if ($result) {
$this->log("file '{$srcFullFileName}' has been moved to '{$destFullFileName}'");
} else {
$this->log("unable to move file from '{$srcFullFileName}' to '{$destFullFileName}'!", Logger::LEVEL_ERROR);
}
return $result;
}
示例10: rename
/**
* Rename a file
*
* @access public
* @param string
* @param string
* @param bool
* @return bool
*/
function rename($old_file, $new_file, $move = FALSE)
{
if (!$this->_is_conn()) {
return FALSE;
}
$result = @ssh2_sftp_rename($this->conn_sftp, $old_file, $new_file);
if ($result === FALSE) {
$this->_error('sftp_unable_to_rename');
return FALSE;
}
return TRUE;
}
示例11: ssh2Rename
function ssh2Rename($oldsourcefilename, $newsourcefilename)
{
$result = ssh2_sftp_rename($this->sftp, $oldsourcefilename, $newsourcefilename);
return $result;
}
示例12: move
/**
* [rename description]
* @param [type] $oldFile [description]
* @param [type] $newFile [description]
* @return [type] [description]
*/
public function move($oldFile, $newFile)
{
if (false === $this->validConn()) {
throw new Exception('invalid connection');
}
if (!($this->sftp = @ssh2_sftp($this->conn))) {
throw new Exception("unable to establish sftp connection with {$host}");
}
return $this->sftp;
if (false === ($result = @ssh2_sftp_rename($this->sftp, $oldFile, $newFile))) {
throw new Exception("unable to rename file");
}
return $result;
}
示例13: rename
/**
* {@inheritdoc}
*/
public function rename(BucketInterface $bucket, $oldname, $newname)
{
if (!$this->exists($bucket, $oldname)) {
throw new ServerException("Unable to rename storage object '{$oldname}', object does not exists at SFTP server.");
}
$location = $this->ensureLocation($bucket, $newname);
if (file_exists($this->getUri($bucket, $newname))) {
//We have to clean location before renaming
$this->delete($bucket, $newname);
}
if (!ssh2_sftp_rename($this->sftp, $this->getPath($bucket, $oldname), $location)) {
throw new ServerException("Unable to rename storage object '{$oldname}' to '{$newname}'.");
}
return $this->refreshPermissions($bucket, $newname);
}
示例14: mv
public function mv($from, $to)
{
return ssh2_sftp_rename($this->_sftp, $from, $to);
}
示例15: rename
public function rename($source, $destination)
{
return @ssh2_sftp_rename($this->handle, $source, $destination);
}