Danny620 Posted September 24, 2012 Share Posted September 24, 2012 Hi, I'm thinking of using this ftp class http://www.shayanderson.com/php/simple-ftp-class-for-php.htm I just wanted to know how I would go about transferring a folder with contents onto a remote server i.e Server Local A Folder – Blog Inside folder Index.php Config.php Images – folder Css – folder To remote server B So I just want to copy the blog folder on server A to remote server B can you provide me with some code using class above? Folder – Blog Inside folder Index.php Config.php Images – folder Css - folder Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2012 Share Posted September 24, 2012 Ummm, what have you tried? (leave out your actual ftp connection details when you post your code) Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/#findComment-1380678 Share on other sites More sharing options...
Danny620 Posted September 24, 2012 Author Share Posted September 24, 2012 i don't know where to start help Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/#findComment-1380680 Share on other sites More sharing options...
Danny620 Posted September 24, 2012 Author Share Posted September 24, 2012 ? Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/#findComment-1380703 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2012 Share Posted September 25, 2012 (edited) <?php $root = 'blog'; // starting folder (relative to where this script is at) // find the folder structure and the files $folders = array(); $files = array(); $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root)); while($it->valid()){ if (!$it->isDot()){ $folders[] = $root .'/'. $it->getSubPath(); // get all folders $files[] = $it->key(); // get all files } $it->next(); } $folders = array_unique($folders); // remove duplicates include "SFTP.php"; $ftp = new SFTP("ftp host name", "ftp user name", "ftp password"); if(!$ftp->connect()) { // connection failed, display last error echo "Connection failed: {$ftp->error}<br />"; } else { echo "Connection successful<br />"; // make the folder structure foreach($folders as $folder){ if($ftp->mkdir($folder)){ echo "Made folder: $folder<br />"; } else { echo "Error: {$ftp->error}<br />"; } } // copy all the files foreach($files as $file){ if($ftp->put($file, $file)){ echo "Copied: $file<br />"; } else { echo "Error: {$ftp->error}<br />"; } } } Edited September 25, 2012 by PFMaBiSmAd editor removed white-space in code, had to redo Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/#findComment-1380753 Share on other sites More sharing options...
Danny620 Posted September 25, 2012 Author Share Posted September 25, 2012 It works on a few F5 hits dont know why here is the link http://stonerigraceway.com/ftp/install.php Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/#findComment-1380811 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2012 Share Posted September 25, 2012 (edited) A) The directory structure you actually have is not what you stated. B) Since A) wasn't true and since most FTP servers cannot create multiple folder levels at one time, the script would need to be changed to create folders one level at a time. C) If this is a one time operation, you should just use a FTP client to make a copy onto your PC, then FTP it onto the new server. D) If you need to use a php script to do this, you should probably hire a programmer. Edited September 25, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/#findComment-1380821 Share on other sites More sharing options...
Danny620 Posted September 25, 2012 Author Share Posted September 25, 2012 How can i change it to create folders one level at a time? my target is to basicly copy a pre configured list of files to remote server all the user would have to do is enter his ftp details, thanks for the help already. Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/#findComment-1380829 Share on other sites More sharing options...
Danny620 Posted September 26, 2012 Author Share Posted September 26, 2012 ? Quote Link to comment https://forums.phpfreaks.com/topic/268756-ftp-help/#findComment-1380988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.