fbemo Posted December 23, 2009 Share Posted December 23, 2009 Hi, I'm writing a code where the script will transfer web files/folder from site A to site B. This is working on cPanel that are using "public_html" but this isn't working on Plesk which are using "httpdocs". It stuck saying; Create Folders Sorry the folder: /images already exists ;while there is no file/folder inside "httpdocs", it is empty. <?php error_reporting(E_ALL ^ E_WARNING); //------------- functions //--------------------------- connect and login to server function ftpconnect($host,$user,$pass) { global $conn; $conn=ftp_connect($host) or die('Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'); //login to server if (!ftp_login($conn,$user,$pass)) { echo 'Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'; exit; } } //-------------------------- close ftp connections function ftpClose($conn) { //close ftp connection ftp_close($conn); } //------------------------ create directory function ftpMkDir($conn,$dirToCreate) { if (!ftp_mkdir($conn,$dirToCreate)) { echo "<p>Sorry the folder: $dirToCreate already exists</p>\n"; exit; } else { echo "<p>Folder: $dirToCreate created</p>\n"; } } ?> Thanks Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 rename the folder images and then try again.. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 rename the folder images and then try again.. I'm sorry, I might not get it clear. But FYI, the"Site B" is empty. There's no such folder named "images". Thanks. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 is this ur entire code..?? Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 Not this is just partial of it, ok here; <?php error_reporting(E_ALL ^ E_WARNING); //------------- functions //--------------------------- connect and login to server function ftpconnect($host,$user,$pass) { global $conn; $conn=ftp_connect($host) or die('Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'); //login to server if (!ftp_login($conn,$user,$pass)) { echo 'Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'; exit; } } //-------------------------- close ftp connections function ftpClose($conn) { //close ftp connection ftp_close($conn); } //------------------------ create directory function ftpMkDir($conn,$dirToCreate) { if (!ftp_mkdir($conn,$dirToCreate)) { echo "<p>Sorry the folder: $dirToCreate already exists</p>\n"; exit; } else { echo "<p>Folder: $dirToCreate created</p>\n"; } } //------------------------ set directory permissions function ftpFolderPermission($conn,$folderChmod) { if (ftp_chmod($conn, 0777, $folderChmod) !== false) { echo "<p>$folderChmod chmoded successfully to 0777</p>\n"; } } //---------------------- copy file to new server function copyFile($conn,$remoteFile,$localFile) { if (ftp_put($conn,$remoteFile,$localFile,FTP_BINARY)) { echo "<p>successfully uploaded $localFile to $remoteFile</p>\n"; } else { echo "<p>There was a problem while uploading $remoteFile</p>\n"; } } //----------- end of functions ------------------------- //get the credentials from user $user = $_POST['username']; //change to ftp username $username = $pass = $_POST['passwd']; //change to ftp password $host = $_POST['urlname']; //change to ftp url if (($user == "") || ($pass == "") || ($host == "")) { echo "Please fill all the details."; } else { //connect to server ftpconnect($host,$user,$pass); echo "<h2>Create Folders</h2>\n"; //create directory ftpMkDir($conn,"/images"); echo "<h2>Set Folder Permissions</h2>\n"; //change folder mermissions to 0777 ftpFolderPermission($conn,"images"); echo "<h2>Upload Files</h2>\n"; //copy file to new server //connection then path to copy file to then path to file on this server copyFile($conn,"index.html","http://www.exampleofwebsite.com/template1/index.html"); ?> Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 try like this <?php error_reporting(E_ALL ^ E_WARNING); //------------- functions //--------------------------- connect and login to server function ftpconnect($host,$user,$pass) { global $conn; $conn=ftp_connect($host) or die('Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'); //login to server if (!ftp_login($conn,$user,$pass)) { echo 'Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'; exit; } } //-------------------------- close ftp connections function ftpClose($conn) { //close ftp connection ftp_close($conn); } //------------------------ create directory function ftpMkDir($conn,$dirToCreate) { if (!ftp_mkdir($conn,$dirToCreate)) { echo "<p>Sorry the folder: $dirToCreate already exists</p>\n"; echo "<p>So continuing with copying the files</p>\n"; copyFile($conn,"index.jpg","image01.jpg"); exit; } else { echo "<p>Folder: $dirToCreate created</p>\n"; } } //------------------------ set directory permissions function ftpFolderPermission($conn,$folderChmod) { if (ftp_chmod($conn, 0777, $folderChmod) !== false) { echo "<p>$folderChmod chmoded successfully to 0777</p>\n"; } } //---------------------- copy file to new server function copyFile($conn,$remoteFile,$localFile) { if (ftp_put($conn,$remoteFile,$localFile,FTP_BINARY)) { echo "<p>successfully uploaded $localFile to $remoteFile</p>\n"; } else { echo "<p>There was a problem while uploading $remoteFile</p>\n"; } } //----------- end of functions ------------------------- //get the credentials from user $user = "ftp"; //change to ftp username $username = $pass = "ftp"; //change to ftp password $host = "192.168.0.35"; //change to ftp url if (($user == "") || ($pass == "") || ($host == "")) { echo "Please fill all the details."; } else { //connect to server ftpconnect($host,$user,$pass); echo "<h2>Create Folders</h2>\n"; //create directory ftpMkDir($conn,"/images"); echo "<h2>Set Folder Permissions</h2>\n"; //change folder mermissions to 0777 ftpFolderPermission($conn,"images"); echo "<h2>Upload Files</h2>\n"; //copy file to new server //connection then path to copy file to then path to file on this server copyFile($conn,"index.jpg","image01.jpg"); } ?> index.jpg is the remote file name and image01.jpg is the local file name. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 try like this <?php error_reporting(E_ALL ^ E_WARNING); //------------- functions //--------------------------- connect and login to server function ftpconnect($host,$user,$pass) { global $conn; $conn=ftp_connect($host) or die('Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'); //login to server if (!ftp_login($conn,$user,$pass)) { echo 'Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'; exit; } } //-------------------------- close ftp connections function ftpClose($conn) { //close ftp connection ftp_close($conn); } //------------------------ create directory function ftpMkDir($conn,$dirToCreate) { if (!ftp_mkdir($conn,$dirToCreate)) { echo "<p>Sorry the folder: $dirToCreate already exists</p>\n"; echo "<p>So continuing with copying the files</p>\n"; copyFile($conn,"index.jpg","image01.jpg"); exit; } else { echo "<p>Folder: $dirToCreate created</p>\n"; } } //------------------------ set directory permissions function ftpFolderPermission($conn,$folderChmod) { if (ftp_chmod($conn, 0777, $folderChmod) !== false) { echo "<p>$folderChmod chmoded successfully to 0777</p>\n"; } } //---------------------- copy file to new server function copyFile($conn,$remoteFile,$localFile) { if (ftp_put($conn,$remoteFile,$localFile,FTP_BINARY)) { echo "<p>successfully uploaded $localFile to $remoteFile</p>\n"; } else { echo "<p>There was a problem while uploading $remoteFile</p>\n"; } } //----------- end of functions ------------------------- //get the credentials from user $user = "ftp"; //change to ftp username $username = $pass = "ftp"; //change to ftp password $host = "192.168.0.35"; //change to ftp url if (($user == "") || ($pass == "") || ($host == "")) { echo "Please fill all the details."; } else { //connect to server ftpconnect($host,$user,$pass); echo "<h2>Create Folders</h2>\n"; //create directory ftpMkDir($conn,"/images"); echo "<h2>Set Folder Permissions</h2>\n"; //change folder mermissions to 0777 ftpFolderPermission($conn,"images"); echo "<h2>Upload Files</h2>\n"; //copy file to new server //connection then path to copy file to then path to file on this server copyFile($conn,"index.jpg","image01.jpg"); } ?> index.jpg is the remote file name and image01.jpg is the local file name. You mean I need to change the index.jpg and image01.jpg? Sorry, I'm new to PHP. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 u put what ever u have given previously i just gave it for your reference also u need to change the hostname,userid and password to what ever u have already given Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 do one thing just chnge this function like this function ftpMkDir($conn,$dirToCreate) { if (!ftp_mkdir($conn,$dirToCreate)) { echo "<p>Sorry the folder: $dirToCreate already exists</p>\n"; echo "<p>So continuing with copying the files</p>\n"; copyFile($conn,"index.jpg","image01.jpg"); exit; } else { echo "<p>Folder: $dirToCreate created</p>\n"; } } Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 It prompts this: Create Folders Sorry the folder: /images already exists So continuing with copying the files There was a problem while uploading index.jpg Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 i think u copied my enitre code.. use this code <?php error_reporting(E_ALL ^ E_WARNING); //------------- functions //--------------------------- connect and login to server function ftpconnect($host,$user,$pass) { global $conn; $conn=ftp_connect($host) or die('Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'); //login to server if (!ftp_login($conn,$user,$pass)) { echo 'Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'; exit; } } //-------------------------- close ftp connections function ftpClose($conn) { //close ftp connection ftp_close($conn); } //------------------------ create directory function ftpMkDir($conn,$dirToCreate) { if (!ftp_mkdir($conn,$dirToCreate)) { echo "<p>Sorry the folder: $dirToCreate already exists</p>\n"; echo "<p>So continuing with copying the files</p>\n"; copyFile($conn,"index.jpg","image01.jpg"); exit; } else { echo "<p>Folder: $dirToCreate created</p>\n"; } } //------------------------ set directory permissions function ftpFolderPermission($conn,$folderChmod) { if (ftp_chmod($conn, 0777, $folderChmod) !== false) { echo "<p>$folderChmod chmoded successfully to 0777</p>\n"; } } //---------------------- copy file to new server function copyFile($conn,$remoteFile,$localFile) { if (ftp_put($conn,$remoteFile,$localFile,FTP_BINARY)) { echo "<p>successfully uploaded $localFile to $remoteFile</p>\n"; } else { echo "<p>There was a problem while uploading $remoteFile</p>\n"; } } //----------- end of functions ------------------------- //get the credentials from user $user = $_POST['username']; //change to ftp username $username = $pass = $_POST['passwd']; //change to ftp password $host = $_POST['urlname']; //change to ftp url if (($user == "") || ($pass == "") || ($host == "")) { echo "Please fill all the details."; } else { //connect to server ftpconnect($host,$user,$pass); echo "<h2>Create Folders</h2>\n"; //create directory ftpMkDir($conn,"/images"); echo "<h2>Set Folder Permissions</h2>\n"; //change folder mermissions to 0777 ftpFolderPermission($conn,"images"); echo "<h2>Upload Files</h2>\n"; //copy file to new server //connection then path to copy file to then path to file on this server copyFile($conn,"index.html","http://www.exampleofwebsite.com/template1/index.html"); } ?> but here one small problem is that if u are running this code on the second server this php function should be changed like this copyFile($conn,"http://www.exampleofwebsite.com/template1/index.html","index.html"); Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 Same prompts like before, I wonder where the script reads that non-existed images folder. httpdocs inside my hosting for that particular domain is really empty. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 Same prompts like before, I wonder where the script reads that non-existed images folder. httpdocs inside my hosting for that particular domain is really empty. is there a form before this code??? Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 I tried with folder "asdas324daff" too, which this is really unique. Impossible to have it on my hosting. But I still getting the same prompts; Create Folders Sorry the folder: /asdas324daff already exists Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 i think u copied my enitre code.. use this code <?php error_reporting(E_ALL ^ E_WARNING); //------------- functions //--------------------------- connect and login to server function ftpconnect($host,$user,$pass) { global $conn; $conn=ftp_connect($host) or die('Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'); //login to server if (!ftp_login($conn,$user,$pass)) { echo 'Could not connect to host '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'; exit; } } //-------------------------- close ftp connections function ftpClose($conn) { //close ftp connection ftp_close($conn); } //------------------------ create directory function ftpMkDir($conn,$dirToCreate) { if (!ftp_mkdir($conn,$dirToCreate)) { echo "<p>Sorry the folder: $dirToCreate already exists</p>\n"; echo "<p>So continuing with copying the files</p>\n"; copyFile($conn,"index.jpg","image01.jpg"); exit; } else { echo "<p>Folder: $dirToCreate created</p>\n"; } } //------------------------ set directory permissions function ftpFolderPermission($conn,$folderChmod) { if (ftp_chmod($conn, 0777, $folderChmod) !== false) { echo "<p>$folderChmod chmoded successfully to 0777</p>\n"; } } //---------------------- copy file to new server function copyFile($conn,$remoteFile,$localFile) { if (ftp_put($conn,$remoteFile,$localFile,FTP_BINARY)) { echo "<p>successfully uploaded $localFile to $remoteFile</p>\n"; } else { echo "<p>There was a problem while uploading $remoteFile</p>\n"; } } //----------- end of functions ------------------------- //get the credentials from user $user = $_POST['username']; //change to ftp username $username = $pass = $_POST['passwd']; //change to ftp password $host = $_POST['urlname']; //change to ftp url if (($user == "") || ($pass == "") || ($host == "")) { echo "Please fill all the details."; } else { //connect to server ftpconnect($host,$user,$pass); echo "<h2>Create Folders</h2>\n"; //create directory ftpMkDir($conn,"/images"); echo "<h2>Set Folder Permissions</h2>\n"; //change folder mermissions to 0777 ftpFolderPermission($conn,"images"); echo "<h2>Upload Files</h2>\n"; //copy file to new server //connection then path to copy file to then path to file on this server copyFile($conn,"index.html","http://www.exampleofwebsite.com/template1/index.html"); } ?> but here one small problem is that if u are running this code on the second server this php function should be changed like this copyFile($conn,"http://www.exampleofwebsite.com/template1/index.html","index.html"); It is from this code. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 I tried with folder "asdas324daff" too, which this is really unique. Impossible to have it on my hosting. But I still getting the same prompts; Create Folders Sorry the folder: /asdas324daff already exists then i think the user id and password which u r using doesnot have the full permissions to create a folder.. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 I tried with folder "asdas324daff" too, which this is really unique. Impossible to have it on my hosting. But I still getting the same prompts; Create Folders Sorry the folder: /asdas324daff already exists then i think the user id and password which u r using doesnot have the full permissions to create a folder.. Nope, it has full rights on it. Btw, the entire code is working on cPanel. It working fine transferring all the files from site A to site B. But when I using another hosting (Plesk), it doesn't working. Site A (cPanel) to Site B (cPanel) = OK Site A (cPanel) to Site B (Plesk) = Not OK Or do I have to assign "public_html" for cPanel user and/or "httpdocs" for Plesk user FYI, this is a script I'm providing to one of community. They just need to select website template they want and just fill in simple credentials (username, url, pass) and hit submit. Then it will automatically upload this template to their hosting in no time. But the problem is, some of users there are using Plesk... most of them.. so I need this to be working on Plesk hosting. Thanks. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 I have an idea but I don't know how to code it; Let suppose the script will first determine whether it is a cPanel hosting or Plesk hosting, if cPanel > run the original script like in this thread if Plesk > locate "httpdocs" and copy all the files/folders into it Anyone can re-code it? Thanks Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 23, 2009 Share Posted December 23, 2009 I have an idea but I don't know how to code it; Let suppose the script will first determine whether it is a cPanel hosting or Plesk hosting, if cPanel > run the original script like in this thread if Plesk > locate "httpdocs" and copy all the files/folders into it Anyone can re-code it? Thanks now i got it out u cannot create a folder at the place of htdocs so i think u are getting this error.. do one thing in the copy file change the command to copyFile($conn,"httpdocs/images/<remotefilename>","<local file>"); Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 23, 2009 Author Share Posted December 23, 2009 echo "<h2>Create Folders</h2>\n"; //create directory ftpMkDir($conn,"httpdocs/images"); echo "<h2>Upload Files</h2>\n"; //copy file to new server //connection then path to copy file to then path to file on this server copyFile($conn,"httpdocs/index.html","http://www.exampleofwebsite.com/template1/index.html"); Yep, it is working... thanks a lot! Btw, before that I would like to know how to Auto detect the hosting is using cPanel or Plesk? If Plesk > Perform ftpMkDir($conn,"httpdocs/images"); else if cPanal > Perform ftpMkDir($conn,"/images"); P.s: Sorry I fall asleep last night Thanks again Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 24, 2009 Share Posted December 24, 2009 actually u cannot determine. coz the cpanel will use the Linux operating system, where as the Pleask is based on the Windows operating system. so u need to give an option in ur tool for the user to mention whether he is using the Cpanel or Pleask then u can perform the operations depending upon user selections. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 24, 2009 Author Share Posted December 24, 2009 actually u cannot determine. coz the cpanel will use the Linux operating system, where as the Pleask is based on the Windows operating system. so u need to give an option in ur tool for the user to mention whether he is using the Cpanel or Pleask then u can perform the operations depending upon user selections. Yep, this is what I'm working for right now.. I need to detect whether it is using public_html or httpdocs.. Quote Link to comment 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.