In php, we can use ftp_connect functions to upload and download files. In fact, this is the same operation on the ftp client. Next I will introduce how to use php to implement it. In php, we can use ftp_connect functions to upload and download files. In fact, this is the same operation on the ftp client. Next I will introduce how to use php to implement it.
Script ec (2); script
The php code is as follows:
The Code is as follows: |
|
$ Ftp_server = 'www .111cn.net '; // server $ Ftp_user_name = '111cn. net'; // User Name $ Ftp_user_pass = 'Password'; // password $ Ftp_port = '21'; // Port $ Ftp_put_dir = 'data/photo/thumb/data2 '; // upload directory $ Ftp_conn_id = ftp_connect ($ ftp_server, $ ftp_port ); $ Ftp_login_result = ftp_login ($ ftp_conn_id, $ ftp_user_name, $ ftp_user_pass ); If ((! $ Ftp_conn_id) | (! $ Ftp_login_result )){ Echo 'failed to connect to the ftp server '; Exit; } Else { Ftp_pasv ($ ftp_conn_id, true); // return the mode. This is a strange sentence. Some ftp servers must execute this sentence. Ftp_chdir ($ ftp_conn_id, $ ftp_put_dir ); $ Ftp_upload = ftp_put ($ ftp_conn_id, '3c264461abdf49de2ddaabc3426ceb65.jpg ', 'data111cn.net3c264461abdf49de2ddaabc3426ceb65.jpg', FTP_BINARY ); // Var_dump ($ ftp_upload); // check whether the write is successful. Ftp_close ($ ftp_conn_id); // disconnect } |
Annotation
The ftp_connect () function creates a new FTP connection.
If the connection succeeds, a connection ID is returned. Otherwise, false is returned.
The ftp_login () function logs in to the specified FTP connection.
The ftp_login () function is used to log on to the FTP server.
This function returns TRUE on success and FALSE and a warning on failure.
If the function is successfully executed, True is returned. If the function fails, False is returned and a warning is given.
The ftp_put () function uploads files to the server.
If the call succeeds, true is returned. If the call fails, false is returned.