Home >Backend Development >PHP Tutorial >How to establish Ftp connection in php_PHP tutorial
This article mainly introduces the method of establishing Ftp connection in php. It analyzes the related functions and usage skills of php to operate FTP with examples, which has certain reference. For reference value, friends in need can refer to it
The example in this article describes the method of establishing Ftp connection in PHP. Share it with everyone for your reference. The specific analysis is as follows:
Today I looked at the ftp function and summarized it:
FTP related functions:
ftp_connect (host, part, timeout) Establish a new ftp connection, host is the server to be connected, part is the port, the default is 21, timeout is the network connection timeout
ftp_login(con,user,password) Log in to ftp, con is the ftp connection established upstream. There is also user user and password password
ftp_close(con) closes the con connection.
ftp_pasv(con,true) turns on the passive transmission mode of con. Data is transferred by the client. Of course, this can only be executed if the login is successful.
ftp_put(con,remove,local,mode) Upload the file with local path to con and name it remove file. mode is the transfer mode (FTP_ASCII, FTP_BINARY)
Example below:
?
3 4 5
|
$host = 'host';
$user = 'user';
$pwd = 'pwd';
$con = ftp_connect($host);
$login = ftp_login($con,$user,$pwd);
echo ftp_put($con,'newname.txt','text.txt',FTP_ASCII); |