Home >Backend Development >PHP Tutorial >How to establish Ftp connection in php, php establish ftp_PHP tutorial
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) Close the con connection.
ftp_pasv(con,true) Turn 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:
$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); ftp_close($con);
I hope this article will be helpful to everyone’s PHP programming design.