Connect to FTP in PHP to upload, download, and delete files.

Source: Internet
Author: User
Tags ftp connection ftp file

PHP ftp transfers files to the server
CopyCode The Code is as follows: <? PHP
// 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 a file using php ftp copy Code the code is as follows: $ file = 'public _ html/old.txt ';
// connect to the FTP server
$ conn_id = ftp_connect ('www .jb51.net ');
// verify the username and password
$ login_result = ftp_login ($ conn_id, $ ftp_user_name, $ ftp_user_pass );
// Delete the specified file
If (ftp_delete ($ conn_id, $ file) {
echo "$ file File deleted successfully N ";
}else {
echo "failed to delete $ file N";
}< br> // disable FTP connection
ftp_close ($ conn_id );
?>

php ftp File Download copy Code 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);
// get the size of the specified file
$ res = ftp_size ($ conn_id, $ file);
if ($ res! =-1) {
echo "$ file size is $ res Byte";
}else {
echo "failed to get remote file size ";
}< br> // 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.