| Server IP : 89.39.208.18 / Your IP : 216.73.217.74 Web Server : LiteSpeed System : User : ( ) PHP Version : 7.4.33 Disable Function : eval,./,ln,passthru,dl,system,exec,popen,shell_exec,posix_getpwuid,posix_uname,ftp_exec,posix_uname,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,get_current_user,getmyuid,getmygid,listen,chgrp,apache_note,apache_setenv,apache_child_terminate,closelog,debugger_off,debugge_on,ini_restore,netscript,escapeshellarg,cmd,backtick,virtual,show_sourc,show_source,pclose,pcntl_exec,datasec,old_offset,ctrl_dir,ini_alter,leak,listen,chgrp,apache_setenv,define_syslog_variables,root,diskfreespace,disk_free_space,disk_total_space,posix_kill,getmyuid,getmygid,apache_child_terminate,php_ini_scanned_files,ls,ps_aux,chown,getrusage,posixc,posame,chgrp,posix_setuid,posix_setsid,posix_setgid,apache_note,apache_setenv,x_getuid,e_ini_file,nfo,SQL,mysql_li,t_dbs,filegroup,highlight_file,ilegetcontents,get_dir,popen,popens,pfsockopen,dos_conv,apache_get_modules,crack_check,crack_closedict,rar_open,bzopen,bzread,bzwrite,shellcode,posix_isatty,posix_getservbyname,escapeshellarg,hypot,pg_host,pos,posix_access,inurl,posix_times,posix_mknod,pclose,ps_fill,symlink,id,escapeshellcmd,php_uname,phpinfo MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home3/mahyarcake/www/wp-content/plugins/duplicator-pro/addons/ftpaddon/src/Utils/ |
Upload File : |
<?php
/**
* @package Duplicator
* @copyright (c) 2022, Snapcreek LLC
*/
namespace Duplicator\Addons\FtpAddon\Utils;
use DateTime;
class FTPUtils
{
const SYS_TYPE_UNIX = 'UNIX';
const SYS_TYPE_WINDOWS_NT = 'WINDOWS_NT';
/**
* Parses a raw list item string into an array
*
* @param string $rawListString Raw list string
* @param string $systemType System type (UNIX or WINDOWS_NT)
*
* @return false|array{name: string, size: int, modified: int, created: int, isDir: bool}|false
*/
public static function parseRawListString($rawListString, $systemType)
{
switch (strtoupper($systemType)) {
case self::SYS_TYPE_UNIX:
return self::parseUnixRawListString($rawListString);
case self::SYS_TYPE_WINDOWS_NT:
return self::parseWindowsRawListString($rawListString);
default:
return false;
}
}
/**
* Returns the info in the raw list item for Windows
*
* @param string $rawListString Raw list string
*
* @return false|array{name: string, size: int, modified: int, created: int, isDir: bool}|false
*/
private static function parseWindowsRawListString($rawListString)
{
//Regex below gets info from raw string on Windows systems
//Dir: 01-01-70 12:00AM <DIR> folder
//File: 01-01-70 12:00AM 4096 file.txt
//Groups: 1 2 3
$regex = '/^(\d{2}-\d{2}-\d{2,4}\s+\d{1,2}:\d{1,2}(?:AM|PM))\s+(<DIR>|\d+)\s+(.+)$/';
if (preg_match($regex, $rawListString, $matches) !== 1) {
return false;
}
$date = DateTime::createFromFormat('m-d-y h:ia', $matches[1]);
$info = [];
$info['name'] = $matches[3];
$info['isDir'] = strtoupper($matches[2]) === '<DIR>';
$info['size'] = $info['isDir'] ? 0 : (int) $matches[2];
$info['modified'] = $date !== false ? $date->getTimestamp() : 0;
$info['created'] = $info['modified'];
return $info;
}
/**
* Returns the info in the raw list item for Unix
*
* @param string $rawListString Raw list string
*
* @return false|array{name: string, size: int, modified: int, created: int, isDir: bool}|false
*/
private static function parseUnixRawListString($rawListString)
{
//Regex below gets info from raw string on UNIX systems
//Example: drwxr-xr-x 2 user group 4096 Jan 1 1970 folder
//Groups: 1 2 3 4 5 6 7
$regex = '/^([drwx\-]{10})\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\w{3}\s+\d{1,2}\s+\d{1,2}:\d{1,2}|\w{3}\s+\d{1,2}\s+\d{4})\s+(.+)$/';
if (preg_match($regex, $rawListString, $matches) !== 1) {
return false;
}
$info = [];
$info['name'] = $matches[7];
$info['isDir'] = $matches[1][0] === 'd';
$info['size'] = $info['isDir'] ? 0 : (int) $matches[5];
$info['modified'] = strtotime($matches[6]);
$info['created'] = $info['modified'];
return $info;
}
}