This article describes the FTP function Ftp_connect, ftp_login and Ftp_chmod usage in PHP. Share to everyone for your reference. The specific methods are as follows:
The Ftp_connect () function establishes a new FTP connection and, if successful, returns a connection identity, or false.
Syntax: Ftp_connect (host,port,timeout), the instance code is as follows:
Copy Code code as follows:
$file = ' public_html/index.php '; Definition file
$conn _id=ftp_connect ($ftp _server); Connecting to the specified FTP server
$login _result=ftp_login ($conn _id, $ftp _user_name, $ftp _user_pass); Log in with the specified user name
if (Ftp_chmod ($conn _id,0644, $file)!==false)//Set the mode of the file
{
echo "$file chmoded successfully to 644n"; Output information
}
Else
{
echo "Could not chmod $filen"; If you set the failed output information
}
Ftp_close ($conn _id); Turn off FTP connections
The Ftp_chmod () function sets the permissions for the specified file on the FTP server, and if successful, the function returns a new permission, or false.
Syntax: Ftp_chmod (ftp_connection,mode,file), code as follows:
Copy Code code as follows:
$ftp _server= "Ftp.jb51.net"; Defining an FTP Server
$ftp _user= "foo"; Define user Name
$ftp _pass= "Bar"; Define the user's corresponding password
$conn _id=ftp_connect ($ftp _server) or Die ("couldn ' t connect to $ftp _server"); Connecting to a specified FTP server
if (@ftp_login ($conn _id, $ftp _user, $ftp _pass))//if successfully logged in
{
echo "Connected as $ftp _user@ $ftp _servern"; Output appropriate information
}
Else
{
echo "couldn ' t connect as $ftp _usern"; Output information that cannot be logged in
}
The Ftp_login () function logs on to the FTP server, returns True if successful, and returns false with a warning if it fails.
Syntax: Ftp_login (Ftp_connection,username,password)
| Parameters |
Describe |
| Ftp_connection |
Required, specify the FTP connection to use (the identifier for the FTP connection). |
| Username |
Required, specify the user name to use for the login. |
| Password |
Required, specify the password to use for the login. |
I hope this article will help you with your PHP program design.