I m trying to upload a file from the Plesk server to the HostGator server using the FTP details I created in HostGator.
The code is from this query. Which I presume works fine. But for some reason, the file is not bing uploaded.
The code goes as:
<?php
$ftp_server = "the.servername";
$ftp_user_name = "the@username";
$ftp_user_pass = "thepassword";
$destination_file = " ";
$source_file = $_FILES['files']['name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
Please note that the destination_file
is empty as while I created the FTP logins in the HostGator, I clearly mentioned the folder the files have to upload. So I left this destination_file
empty.
Now when I try to upload the error echo's as
Connected to ftp.vdofyfilex.com, for user files_from_vdofy@vdofyfilex.comFTP upload has failed!
As you can see, the connection was successful but the file was not uploading. could be because of destination_file
is empty.
Things I have tried with $destination_file
:
$destination_file = 'added the full domain with directory'
- Added a sub folder as temp and
$destination_file = 'temp/'
- Added a sub folder as temp and
$destination_file = 'full domain with directory + temp/'
$destination_file = ''
None of 'em worked.
Any help is greatly appreciated.