PHP implementation FTP upload download file example

Source: Internet
Author: User
Tags ftp ftp connection

The code for PHP is as follows

The code is as follows Copy Code

$ftp _server= ' www.111cn.net ';//server
$ftp _user_name= ' 111cn.net ';//user name
$ftp _user_pass= ' password ';//password
$ftp _port= ' 21 ';//Port
$ftp _put_dir= ' data/photo/thumb/data2 ';//upload Directory

$ftp _conn_id = Ftp_connect ($ftp _server, $ftp _port);
$ftp _login_result = Ftp_login ($ftp _conn_id, $ftp _user_name, $ftp _user_pass);

if (! $ftp _conn_id) | | (! $ftp _login_result)) {
Echo ' failed to connect to FTP server ';
Exit
}else{

FTP_PASV ($ftp _conn_id,true); Return to the pattern, this is strange, some FTP server must be executed this sentence

Ftp_chdir ($ftp _conn_id, $ftp _put_dir);
$ftp _upload = ftp_put ($ftp _conn_id, ' 3c264461abdf49de2ddaabc3426ceb65.jpg ', ' Data111cn.net3c264461abdf49de2ddaabc3426ceb65.jpg ', ftp_binary);
Var_dump ($ftp _upload);//See if Write succeeded
Ftp_close ($ftp _conn_id); Disconnect
}

Annotations

The Ftp_connect () function establishes a new FTP connection.

If successful, returns a connection identity, or false.

The Ftp_login () function logs in to the specified FTP connection.
The Ftp_login () function is to log on to the FTP server.

This function returns TRUE to success and FALSE and a warning on failure.
Returns true if the function succeeds, and a warning if the failure returns false.

The Ftp_put () function uploads the file to the server.

Returns true if successful, and returns False if it fails.

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.