Use the php Tutorial to connect to the server, and connect to the imap server. Finally, use the code written in php to upload and download files.
The code is as follows: |
Copy code |
<? Php // Connect to the imap server, and the imap port is 143. $ Mbox = imap_open ("{localhost: 143} inbox", "user_id", "password "); // Connect to the pop3 server. The pop3 port is 110. $ Mbox = imap_open ("{localhost/pop3: 110} inbox", "user_id", "password "); // Connect to the nntp server. The port number of nntp is 119. $ Nntp = imap_open ("{localhost/nntp: 119} comp. test ","",""); ?> |
Email sending function mail
The code is as follows: |
Copy code |
<? Php Mail ("163@111cn.net", "welcome", "hello, hello! "); ?>
|
The code is as follows: |
Copy code |
<? Php // Connect to the imap server $ Mbox = imap_open ("{imap.example.org}", "username", "password", op_halfopen) Or die ("connection failed:". imap_last_error ()); $ List = imap_getmailboxes ($ mbox, "{imap.example.org }","*"); If (is_array ($ list )){ Foreach ($ list as $ key => $ val ){ Echo "($ key )"; Echo imap_utf7_decode ($ val-> name ).","; Echo "'". $ val-> delimiter ."',"; Echo $ val-> attributes. "<br/> n "; } } Else { Echo "imap_getmailboxes failed:". imap_last_error (). "n "; } // Close the imap connection Imap_close ($ mbox ); ?>
|
Connect to the ftp server
The code is as follows: |
Copy code |
<? Php // Open the file to be uploaded $ File = 'demofile.txt '; $ Fp = fopen ($ file, 'r '); // Connect to the ftp server $ Conn_id = ftp_connect ($ ftp_server ); // Log on to the ftp server $ Login_result = ftp_login ($ conn_id, $ ftp_user_name, $ ftp_user_pass ); // Upload a file If (ftp_fput ($ conn_id, $ file, $ fp, ftp_ascii )){ Echo "$ file uploaded successfully n "; } Else { Echo "failed to upload $ file n "; } // Close the ftp connection Ftp_close ($ conn_id ); // Close the opened Upload file Fclose ($ fp ); ?> |
Ftp file upload/download
The code is as follows: |
Copy code |
<? Php $ File = 'somefile.txt '; $ Remote_file = 'readme.txt '; // Connect to the ftp server $ Conn_id = ftp_connect ($ ftp_server ); // Log on with the user name and password $ Login_result = ftp_login ($ conn_id, $ ftp_user_name, $ ftp_user_pass ); // Upload a file If (ftp_put ($ conn_id, $ remote_file, $ file, ftp_ascii )){ Echo "successfully uploaded $ file n "; } Else { Echo "failed to upload $ file n "; } // Close the ftp connection Ftp_close ($ conn_id ); ?>
|
Delete files through ftp
The code is as follows: |
Copy code |
<? Php $ File = 'public _ html/old.txt '; // Connect to the ftp server $ Conn_id = ftp_connect ($ ftp_server ); // 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 ); ?>
|
Obtain the remote file size through ftp
The code is as follows: |
Copy code |
<? Php $ File = 'somefile.txt '; // Connect to the ftp server $ Conn_id = ftp_connect ($ ftp_server ); // Verify the user name and password $ 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 ); ?> |