It retrieves a file from the FTP server and writes it to a local file
Example
<?php
$fp = fopen(“test.txt”, ‘w’);
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
$ret = ftp_nb_get($ftpId, $fp, “test”, FTP_BINARY, filesize(“test”));
while ($dest == FTP_MOREDATA) {
$dest = ftp_nb_continue($ftpId);
}
ftp_close($ftpId);
fclose($fp);
?>
It stores a file from an open file to the FTP server
Example
<?php
$fp = fopen(“test.txt”, ‘w’);
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
$dest = ftp_nb_fput($conn_id, “text.txt”, $fp, FTP_BINARY);
while ($dest == FTP_MOREDATA) {
$dest = ftp_nb_continue($ftpId);
}
ftp_close($ftpId);
fclose($fp);
?>
It retrieves a file from the FTP server and writes it to an open file
Example
<?php
$fp = fopen(“test.txt”, ‘w’);
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
$dest = ftp_nb_fget($conn_id, $fp, “test.txt”, FTP_BINARY);
while ($dest == FTP_MOREDATA) {
$dest = ftp_nb_continue($ftpId);
}
ftp_close($ftpId);
fclose($fp);
?>
Continues retrieving/sending a file
Example
<?php
$fp = fopen(“test.txt”, ‘w’);
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
$dest = ftp_nb_fget($conn_id, $fp, “test.txt”, FTP_BINARY);
while ($dest == FTP_MOREDATA) {
$dest = ftp_nb_continue($ftpId);
}
ftp_close($ftpId);
fclose($fp);
?>
It creates a directory on the FTP server
Example
<?php
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
ftp_mkdir($ftpId, “tets”) or die(“Failed”);
ftp_close($ftpId);
?>
It returns the last modified time of the given file
Example
<?php
$ftpId = ftp_connect(‘ftp.phpcodez.com’);
$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);
echo date(“D M Y H i s”,ftp_mdtm($ftpId, “test.txt”));
ftp_close($ftpId);
?>
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);
?>
Zend | Magento Certified PHP | eCommerce Architect