Jump to content

FTP working on cPanel but not in Plesk?


fbemo

Recommended Posts

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

Link to comment
Share on other sites

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");

?>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";
   }
}

Link to comment
Share on other sites

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");

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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  ;)

Link to comment
Share on other sites

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>");

Link to comment
Share on other sites

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 :P

 

Thanks again

Link to comment
Share on other sites

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.

:P

Link to comment
Share on other sites

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.

:P

 

Yep, this is what I'm working for right now.. I need to detect whether it is using public_html or httpdocs..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.