Created
May 28, 2017 07:50
-
-
Save rintoug/53e99863e4cbad3f5c6032570b257048 to your computer and use it in GitHub Desktop.
Connect and Handle Files in FTP Server using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// FTP server details | |
$ftpHost = 'ftp.host.com'; | |
$ftpUsername = 'tutsplanet'; | |
$ftpPassword = 'xxxxxxxxxx'; | |
// 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"; | |
} | |
// local & server file path | |
$localDirFilePath = 'test1.php'; | |
$remoteDirFilePath = 'public_html/test1.php'; | |
// downloading the file | |
if(ftp_get($connId, $localDirFilePath, $remoteDirFilePath, FTP_BINARY)){ | |
echo "File downlaod successful - $localDirFilePath"; | |
}else{ | |
echo "There is an error while downloading $remoteDirFilePath"; | |
} | |
// close the connection | |
ftp_close($connId); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment