Skip to content

Instantly share code, notes, and snippets.

@rintoug
Created May 28, 2017 07:52
Show Gist options
  • Save rintoug/1fd76c162574dde041cd82cf58c1a017 to your computer and use it in GitHub Desktop.
Save rintoug/1fd76c162574dde041cd82cf58c1a017 to your computer and use it in GitHub Desktop.
Connect and Handle Files in FTP Server using PHP
<?php
// FTP server details
$ftpHost = 'ftp.host.com';
$ftpUsername = 'tutsplanet';
$ftpPassword = 'xxxxxxxx';
// open an FTP connection
$connId = ftp_connect($ftpHost) or die("Couldn't connect to $ftpHost");
// login to FTP
if(@ftp_login($connId, $ftpUsername, $ftpPassword)){
echo "Connected as $ftpUsername@$ftpHost";
}else{
echo "Couldn't connect as $ftpUsername";
}
// server file path
$file = 'public_html/test1.php';
// deleting the file
if(ftp_delete($connId, $file)){
echo "$file deleted successful";
}else{
echo "There is an error while deleting $file";
}
// close the connection
ftp_close($connId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment