Php connection ftp implementation file upload, download, delete file instance code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags ftp connection ftp file
Connect to ftp in php to upload, download, and delete files. The code for transferring a file to the server using phpftp is as follows :? Php starts $ retftp_nb_get ($ my_connection, test, README, FTP_BINARY, filesize (test); or: $ retftp_nb _ Php ftp transfers files to the server

The code is as follows:


// Start
$ Ret = ftp_nb_get ($ my_connection, "test", "README", FTP_BINARY,
Filesize ("test "));
// Or: $ ret = ftp_nb_get ($ my_connection, "test", "README ",
// FTP_BINARY, FTP_AUTORESUME );
While ($ ret = FTP_MOREDATA ){

// Other code can be inserted.
Echo ".";
// Continue transmission...
$ Ret = ftp_nb_continue ($ my_connection );
}
If ($ ret! = FTP_FINISHED ){
Echo "Download error ...";
Exit (1 );
}
?>


Delete files using php ftp

The code is as follows:


$ File = 'public _ html/old.txt ';
// Connect to the FTP server
$ Conn_id = ftp_connect ('www .jb51.net ');
// Verify the user name and password
$ Login_result = ftp_login ($ conn_id, $ ftp_user_name, $ ftp_user_pass );
// Delete a specified object
If (ftp_delete ($ conn_id, $ file )){
Echo "$ file deleted successfully n ";
} Else {
Echo "failed to delete $ file n ";
}
// Close the FTP connection
Ftp_close ($ conn_id );
?>


Php ftp file download

The code is as follows:


$ File = 'somefile.txt ';
// Connect to the FTP server
$ Conn_id = ftp_connect ($ ftp_server );
// Verify the username and password www. jb51. net
$ Login_result = ftp_login ($ conn_id, $ ftp_user_name, $ ftp_user_pass );
// Obtain the size of the specified object
$ Res = ftp_size ($ conn_id, $ file );
If ($ res! =-1 ){
Echo "$ file size: $ res bytes ";
} Else {
Echo "failed to get the remote file size ";
}
// Close the FTP connection
Ftp_close ($ conn_id );
?>

The http://www.bkjia.com/PHPjc/322020.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322020.htmlTechArticlephp ftp transfers the file to the server code is as follows :? Php // start $ ret = ftp_nb_get ($ my_connection, "test", "README", FTP_BINARY, filesize ("test"); // or: $ ret = ftp_nb _...

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.