/** * Connect to FTP Server * @param $scheme FTP protocol (ftp|ftps) * @param $host The FTP host * @param $user The login * @param $pwd The password * @return Boolean */ public static function connectToHost($scheme, $host, $port, $user, $pwd){ if(!$port){ $port = 21; } if(strcmp($scheme,'ftps') == 0){ self::$conn = ftp_ssl_connect($host, $port); }else{ self::$conn = ftp_connect($host, $port); } $loginResult = ftp_login(self::$conn, $user, $pwd); if(self::$conn && $loginResult){ ftp_pasv(self::$conn, FALSE); return TRUE; } return FALSE; }
$ow = urldecode(trim($_GET['o'])); if(strcmp(substr($url,0,6), 'ftp://') != 0 && strcmp(substr($url,0,7), 'ftps://') != 0){ $url = 'ftp://'.$url; } $url = parse_url($url); if(!isset($url['scheme']) || !isset($url['host']) || !isset($url['user']) || !isset($url['pass']) || !isset($url['path'])){ OC_ocDownloaderPB::setError($l->t('Wrong URL')); }else{ $port = 0; if(isset($url['port'])){ $port = $url['port']; } if(!OC_ocDownloaderFTP::connectToHost($url['scheme'], $url['host'], $port, $url['user'], $url['pass'])){ OC_ocDownloaderPB::setError($l->t('Connection timeout')); }else{ if(OC_ocDownloaderFTP::isDir($url['path'])){ OC_ocDownloaderPB::setError($l->t('Enter a File URL')); OC_ocDownloaderFTP::closeConnection(); }else{ OC_ocDownloaderFTP::getFile($url['path'], $l, $ow); } } } } ?> </body> </html>