It can be used to log in to an FTP connection
Example
<?php
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
?>
It can be used to log in to an FTP connection
Example
<?php
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
?>
It downloads a file from the FTP server
Example
<?php
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
ftp_get($ftpId, “local.text”, ‘server.txt’, FTP_BINARY) or die(“Failed”);
ftp_close($ftpId);
?>
It retrieves various runtime behaviours of the current FTP stream
Example
<?php
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
$disconnect = ftp_get_option($ftpId, FTP_TIMEOUT_SEC);
ftp_close($ftpId);
?>
It uploads from an open file to the FTP server
Example
<?php
$fp = fopen(“test.txt”, ‘r’);
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
ftp_fput($ftpId, “”test.txt””, $fp, FTP_ASCII)
ftp_close($ftpId);
fclose($fp);
?>
It downloads a file from the FTP server and saves to an open file
Example
<?php
$fp = fopen(“test.txt”, ‘w’);
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
ftp_fget($ftpId, $fp, “ftp.txt”, FTP_ASCII, 0) or die (“Failed”);
ftp_close($ftpId);
fclose($fp);
?>
It requests execution of a command on the FTP server
Example
<?php
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
ftp_exec($ftpId, “ls”) or die(“Failed”);
ftp_close($ftpId);
?>
It deletes a file on the FTP server
Example
<?php
$fName=”test”;
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
ftp_delete($ftpId, $fName)
ftp_close($ftpId);
?>
It opens an FTP connection
Example
<?php
$fName=”test”;
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
?>
It closes an FTP connection
Example
<?php
$fName=”test”;
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
ftp_chmod($ftpId, 0777,$fName or die(“Failed”);
ftp_close($ftpId);
?>
It sets permissions on a file via FTP
Example
<?php
$fName=”test”;
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
ftp_chmod($ftpId, 0777,$fName or die(“Failed”);;
?>