FTP function (PHP)

zhaozj2021-02-16  77

/ / Establish a connection example $ conn_id = ftp_connect ($ ftp_server); // Login, return BOOL value $ login_result = ftp_login ($ ftp_user_user_name, $ ftp_user_pass); if (($ conn_id) || (! $ Login_Result) ) {Echo "login server: $ ftp_server username: $ ftp_user_name failed"; Die;} else {echo "login server: $ ftp_server, username: $ ftp_user_name success";}

// Download the file IF above the FTP server (FTP_GET ($ conn_id, $ server_file, $ server_file, ftp_binary) {echo "successfully downloaded $ server_file / n";} else {echo "Download failed / N";

// Number of groups to download $ DFILES = DOWNFILES ($ ServerFile, $ local_file);

// Download one of the files / / per download one by one to download one, delete one. Foreach ($ DFILES AS $ DKEY) {IF (ftp_get ($ conn_id, $ dkey, $ dkey, ftp_binary)) {echo "Download Success $ DKEY
"; if (ftp_delete ($ conn_id, $ dkey) {echo "Successfully remove $ DKEY / N
";} else {echo "delete $ DKEY / N
";}} else {echo "download failed $ dkey / n
;}}

Function getFile ($ filename) {// Get Contents of a file Into a string $ handle = fopen ($ filename, "r"); $ contents = fread ($ HANDE, FileSize) -2); fclose ($ 5); fclose ($ FileName); fclose Handle; $ test = split ("/ r / n", $ contents; return $ test;}

Function DownFiles ($ serverfile, $ localfile) {$ files = getfile ("listfile.txt"); Foreach ($ files as $ key) {echo $ key. "
"; $ keysp = split ("", $ Key); $ localfiles = getfile ("listfile2.txt"); $ had = false; foreach ($ localfiles as $ key2) {$ key2sp = split ("", $ key2); if ($ keySp [1] == $ key2sp [1]) {Echo "I Have". $ key. "
"; $ had = true; if ($ keySP [0])> Strtotime ($ key2sp [0])) $ HAD = False; Break;}} echo $ had. "
"; if (! $ Had) $ downfiles = $ downfiles. "" $ KeySp [1];} Echo $ downfiles; $ downfilesp = split ("", $ downfiles; return $ downfilesp;}?>

转载请注明原文地址:https://www.9cbs.com/read-15804.html

New Post(0)