Tag Archives: CPanel

How to do server to server ftp transfer in PHP

It is quite difficult to transfer web site from one server to another. Here is a solution for server to server ftp transfer.

  • Zip the required files as one file. The zipping feature is usually available in your web hosting control panel’s file manager.
  • Upload the below mentioned script on the source server.
  • Run the script on the source server.
  • This will transfer files from one server to the other.
  • Unzip the files on the destination server.
This script can be used for other purposes as well.

<?php
$server = “ftp.you-server.com”; //address of ftp server (leave out ftp://)
$ftp_user_name = “userName”; // Username
$ftp_user_pass = “passwordHere”; // Password
$source = “/home/folder/public_html/filename.ext”;
$dest = “/public_html/filename.ext”;
$mode=”FTP_BINARY”;
$connection = ftp_connect($server);

$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);

if (!$connection || !$login) { die(‘Connection attempt failed!’); }

$upload = ftp_put($connection, $dest, $source, FTP_BINARY);

if (!$upload) { echo ‘FTP upload failed!’; }

ftp_close($connection);
echo “done”;
?>

How to set a cron job in CPanel to call a PHP or Web Page

To set a cron job in Cpanel to call a PHP or web page at any given times, do the following.

Go to Cpanel of your web site.

Log in to it.

Go to Cron Jobs. It is under the section called “Advanced”.

Cron Section

Click on it.

This will take you to a new screen as below.

Set Cron Job

One this screen, select the frequency of your choice from “Common Settings”.

Set Cron Job

In the “Command” text box, type the following syntax where http://www.your-site-name.com is the name of your web site.

curl -s http://www.your-web-site.com/path-to-your-file.php>/dev/null 2>&1

*Note:
Sometimes you configure your web site using .htaccess file to open it with or without “www” when someone types the URL. Make sure to follow the same rule here.