Php ftp_connect () ftp_login () ftp_chmod () function and instance

Source: Internet
Author: User

The ftp_connect () function creates a new ftp connection.

If the connection succeeds, a connection ID is returned. Otherwise, false is returned.

Syntax
Ftp_connect (host, port, timeout)

*/
$ File = 'public _ html/index. php tutorial '; // define a file
$ Conn_id = ftp_connect ($ ftp_server); // connect to the specified ftp Server
$ Login_result = ftp_login ($ conn_id, $ ftp_user_name, $ ftp_user_pass); // Log On with the specified user name
If (ftp_chmod ($ conn_id, 0644, $ file )! = False) // sets the file mode.
{
Echo "$ file chmoded successfully to 644n"; // output information
}
Else
{
Echo "cocould not chmod $ filen"; // output information if the setting fails
}
Ftp_close ($ conn_id); // close the ftp connection

/*
The ftp_chmod () function sets the permissions for the specified file on the ftp server.

If the operation succeeds, the function returns the new permission. Otherwise, false is returned.

Syntax
Ftp_chmod (ftp_connection, mode, file)
*/

$ Ftp_server = "ftp.example.com"; // defines the ftp server
$ Ftp_user = "foo"; // define the user name
$ Ftp_pass = "bar"; // defines the user's password.
$ Conn_id = ftp_connect ($ ftp_server) or die ("couldn't connect to $ ftp_server"); // connect to the specified ftp Server
If (@ ftp_login ($ conn_id, $ ftp_user, $ ftp_pass) // if logon is successful
{
Echo "connected as $ ftp_user @ $ ftp_servern"; // output the corresponding information
}
Else
{
Echo "couldn't connect as $ ftp_usern"; // output information that cannot be logged on
}
/*

The ftp_login () function is used to log on to the ftp server.

If the call succeeds, true is returned. If the call fails, false is returned and a warning is issued.

Syntax
Ftp_login (ftp_connection, username, password) parameter description
Ftp_connection is required. Specifies the ftp connection to be used (the ftp connection identifier ).
Username is required. Specifies the username used for logon.
Password is required. Specifies the logon password.

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.