02/10/2018, 18:09
Kết nối FTP bằng PHP
Lập trình PHP: Kết nối FTP Server bằng PHP . <? //connect to server if(!($ftp = ftp_connect("localhost"))) { print("Unable to connect!<br />n"); exit(); } print("Connected.<br ...
Lập trình PHP: Kết nối FTP Server bằng PHP .
<?Bình luận
//connect to server
if(!($ftp = ftp_connect("localhost")))
{
print("Unable to connect!<br />n");
exit();
}
print("Connected.<br />n");
//log in
if(!ftp_login($ftp, "anonymous", "corephp@localhost"))
{
print("Unable to login!<br />n");
exit();
}
print("Logged In.<br />n");
//print system type
print("System Type: " . ftp_systype($ftp) . "<br />n");
//make sure passive mode is off
ftp_pasv($ftp, FALSE);
//get working directory
print("Working Directory: " . ftp_pwd($ftp) . "<br />n");
//get files in raw format
print("Raw List:<br />n");
foreach(ftp_rawlist($ftp, ".") as $line)
{
print("$line<br />n");
}
print("<br />n");
//move to pub directory
if(!ftp_chdir($ftp, "pub"))
{
print("Unable to go to the pub directory!<br />n");
}
print("Moved to pub directory.<br />n");
//get a list of files
print("Files:<br />n");
foreach(ftp_nlist($ftp, ".") as $filename)
{
print("$filename<br />n");
}
print("<br />n");
//return to root directory
if(!ftp_cdup($ftp))
{
print("Failed to move up a directory!<br />n");
}
//close connection
ftp_quit($ftp);
?>