PHP ftp upload, download, delete server file instance

Source: Internet
Author: User
Tags ftp php tutorial ftp transfer

PHP Tutorial FTP transfer files to server

<?php
Begin
$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) {

You can insert additional code
echo ".";
Continue to send ...
$ret = ftp_nb_continue ($my _connection);
}
if ($ret!= ftp_finished) {
echo "Download error ...";
Exit (1);
}
?>

PHP FTP Delete file

<?php
$file = ' public_html/old.txt ';
Connecting to an FTP server
$conn _id = ftp_connect (' www.111cn.net ');
Verifying user name 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 Delete succeeded n";
} else {
echo "Delete $file file failed n";
}
Turn off FTP connections
Ftp_close ($conn _id);
?>

PHP ftp Download file

<?php
$file = ' somefile.txt ';
Connecting to an FTP server
$conn _id = ftp_connect ($ftp _server);
Verify user name and password www.111cn.net
$login _result = Ftp_login ($conn _id, $ftp _user_name, $ftp _user_pass);
Gets the size of the specified file
$res = Ftp_size ($conn _id, $file);
if ($res!=-1) {
echo "$file file size is $res byte";
} else {
echo "Get remote file size failed";
}
Turn off FTP connections
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.