Home  >  Article  >  Backend Development  >  How to establish Ftp connection in php_PHP tutorial

How to establish Ftp connection in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:05:14937browse

How to establish Ftp connection in php

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:

?

1

2

3

4

5

6

7

$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);

1 2

3

4 5

67
$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. http://www.bkjia.com/PHPjc/963974.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963974.htmlTechArticleHow to establish Ftp connection in php. This article mainly introduces the method of establishing Ftp connection in php, and analyzes the php operation with examples. The related functions and usage techniques of FTP have certain reference value. Friends in need...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn