Example code for uploading, downloading and deleting files by connecting to ftp under PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:36:57
Original
1239 people have browsed it

php ftp transfer files to server

Copy code 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) {

// You can insert other code
echo "." ;
// Continue transmitting...
$ret = ftp_nb_continue ($my_connection);
}
if ($ret != FTP_FINISHED) {
echo "Download error..." ;
exit(1);
}
?>

php ftp delete file
Copy the code The code is as follows:

$file = 'public_html/old.txt';
// Connect to FTP server
$ conn_id = ftp_connect('www.jb51.net');
// Verify username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Delete specified file
if (ftp_delete($conn_id, $file)) {
echo "$file file deleted successfully";
} else {
echo "Deletion of $file file failed";
}
//Close FTP connection
ftp_close($conn_id);
?>

php ftp download file
Copy code The code is as follows:

$file = 'somefile.txt';
// Connect to FTP server
$conn_id = ftp_connect($ftp_server);
//Verify username and password www.jb51 .net
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//Get the specified file Size
$res = ftp_size($conn_id, $file);
if ($res != -1) {
echo "$file file size is $res bytes";
} else {
echo "Failed to obtain remote file size";
}
//Close FTP connection
ftp_close($conn_id);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322020.htmlTechArticlephp ftp transfer files to the server. Copy the code as follows: ?php // Start $ret = ftp_nb_get ($my_connection, "test", "README", FTP_BINARY, filesize("test")); // or: $ret = ftp_nb_...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!