Phpftp upload, download, and delete Server File instances-PHP source code

Source: Internet
Author: User
Tags ftp connection ftp file ftp transfer
Phpftp upload, download, delete Server File instances php ftp upload, download, delete Server File instances

Script ec (2); script

Php tutorial ftp Transfer file to server

// 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

$ File = 'public _ html/old.txt ';
// Connect to the FTP server
$ Conn_id = ftp_connect ('www .111cn.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

$ File = 'somefile.txt ';
// Connect to the FTP server
$ Conn_id = ftp_connect ($ ftp_server );
// Verify the username and password www.111cn.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 );
?>

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.