From b1df1e8403f4f24462384dc0f3457cbeeed6109f Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Wed, 19 Aug 2015 06:36:04 +0100 Subject: [PATCH] Use ftpStart and ftpEnd functions --- lib/file-control-xhr.php | 30 +++++++++--------------------- lib/file-control.php | 10 +++------- lib/get-branch.php | 10 +++------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/lib/file-control-xhr.php b/lib/file-control-xhr.php index f0a9176..9a3da4d 100644 --- a/lib/file-control-xhr.php +++ b/lib/file-control-xhr.php @@ -190,12 +190,8 @@ if (!$error && $_GET['action']=="save") { // FTP Saving if (isset($ftpSite)) { - // Establish connection, result, maybe use pasv and alert error if no good connection - $ftpConn = ftp_connect($ftpHost); - $ftpLogin = ftp_login($ftpConn, $ftpUser, $ftpPass); - if ($ftpPasv) { - ftp_pasv($ftpConn, true); - } + ftpStart(); + // Show user warning if no good connection if (!$ftpConn || !$ftpLogin) { $doNext .= 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; } @@ -209,7 +205,7 @@ if (!$error && $_GET['action']=="save") { if (!ftpWriteFile($ftpConn, $ftpFilepath, $contents, $ftpMode)) { $doNext .= 'top.ICEcoder.message("Sorry, could not write '.$ftpFilepath.' at '.$ftpHost.'");'; } - ftp_close($ftpConn); + ftpEnd(); // Local saving } else { // Newly created files have the perms set too @@ -342,12 +338,8 @@ if (!$error && $_GET['action']=="newFolder") { $updateFM = false; // FTP if (isset($ftpSite)) { - // Establish connection, result, maybe use pasv and alert error if no good connection - $ftpConn = ftp_connect($ftpHost); - $ftpLogin = ftp_login($ftpConn, $ftpUser, $ftpPass); - if ($ftpPasv) { - ftp_pasv($ftpConn, true); - } + ftpStart(); + // Show user warning if no good connection if (!$ftpConn || !$ftpLogin) { $doNext = 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; } else { @@ -358,7 +350,7 @@ if (!$error && $_GET['action']=="newFolder") { $updateFM = true; } } - ftp_close($ftpConn); + ftpEnd(); // Local } else { mkdir($file, octdec($ICEcoder['newDirPerms'])); @@ -661,12 +653,8 @@ if (!$error && $_GET['action']=="perms") { $updateFM = false; // FTP if (isset($ftpSite)) { - // Establish connection, result, maybe use pasv and alert error if no good connection - $ftpConn = ftp_connect($ftpHost); - $ftpLogin = ftp_login($ftpConn, $ftpUser, $ftpPass); - if ($ftpPasv) { - ftp_pasv($ftpConn, true); - } + ftpStart(); + // Show user warning if no good connection if (!$ftpConn || !$ftpLogin) { $doNext = 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; } else { @@ -677,7 +665,7 @@ if (!$error && $_GET['action']=="perms") { $updateFM = true; } } - ftp_close($ftpConn); + ftpEnd(); // Local } else { chmod($file,octdec(numClean($_GET['perms']))); diff --git a/lib/file-control.php b/lib/file-control.php index 18df5db..4f6d42c 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -86,19 +86,15 @@ if ($_GET['action']=="load") { // Get file over FTP? if (isset($ftpSite)) { - // Establish connection, result, maybe use pasv and alert error if no good connection - $ftpConn = ftp_connect($ftpHost); - $ftpLogin = ftp_login($ftpConn, $ftpUser, $ftpPass); - if ($ftpPasv) { - ftp_pasv($ftpConn, true); - } + ftpStart(); + // Show user warning if no good connection if (!$ftpConn || !$ftpLogin) { die('alert("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");top.ICEcoder.serverMessage();top.ICEcoder.serverQueue("del",0);'); exit; } // Get our file contents and close the FTP connection $loadedFile = toUTF8noBOM(ftpGetContents($ftpConn, $ftpRoot.$fileLoc."/".$fileName, $ftpMode)); - ftp_close($ftpConn); + ftpEnd(); // Get local file } else { $loadedFile = toUTF8noBOM(file_get_contents($file,false,$context),true); diff --git a/lib/get-branch.php b/lib/get-branch.php index 023ced3..76dc7c2 100644 --- a/lib/get-branch.php +++ b/lib/get-branch.php @@ -124,12 +124,8 @@ $dirArray = $filesArray = $finalArray = array(); // Get dir/file list over FTP if (isset($ftpSite)) { - // Establish connection, result, maybe use pasv and alert error if no good connection - $ftpConn = ftp_connect($ftpHost); - $ftpLogin = ftp_login($ftpConn, $ftpUser, $ftpPass); - if ($ftpPasv) { - ftp_pasv($ftpConn, true); - } + ftpStart(); + // Show user warning if no good connection if (!$ftpConn || !$ftpLogin) { die(''); exit; @@ -138,7 +134,7 @@ if (isset($ftpSite)) { $ftpList = ftpGetList($ftpConn, $ftpRoot.$location); $finalArray = $ftpList['simpleList']; $ftpItems = $ftpList['detailedList']; - ftp_close($ftpConn); + ftpEnd(); // or get local list } else { $finalArray = scanDir($scanDir.$location);