Ftp_connect, Ftp_login and Ftp_chmod usage _php techniques for FTP functions in PHP

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.