From 01dc2f7943c5efc6f5461512ac5f6873c3ac41e6 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Thu, 13 Aug 2015 09:16:11 +0100 Subject: [PATCH] FTP control started, with list, open and save Function added to get a raw list from the FTP connection and work with this string to return simple and detailed lists as arrays to use Get contents function added to get content from file over FTP and stream it back as the return Finally, function added to save over FTP --- lib/ftp-control.php | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/ftp-control.php diff --git a/lib/ftp-control.php b/lib/ftp-control.php new file mode 100644 index 0000000..f4d116a --- /dev/null +++ b/lib/ftp-control.php @@ -0,0 +1,48 @@ + $simpleList, 'detailedList' => $detailedList); + } + return false; +} + +// Get contents over FTP +function ftpGetContents($ftpConn, $filepath, $ftpMode) { + // Create temp handler, this type needed for extended char set + $tempHandle = fopen('php://temp', 'r+'); + + // Get file from FTP assuming that it exists + ftp_fget($ftpConn, $tempHandle, $filepath, $ftpMode, 0); + + // Return our content + return stream_get_contents($tempHandle, -1, 0); +} + +// Write file contents over FTP +function ftpWriteFile($ftpConn, $filepath, $contents, $ftpMode) { + // Create temp handler, this type needed for extended char set + $tempHandle = fopen('php://temp', 'r+'); + + // Write contents to handle and rewind head + fwrite($tempHandle, $contents); + rewind($tempHandle); + + // Write our content and return true/false + return ftp_fput($ftpConn, $filepath, $tempHandle, $ftpMode, 0); +} +?> \ No newline at end of file