Tag Archives: FTP

ftp_mkdir()

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

?>

ftp_mdtm()

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

?>

ftp_get()

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

?>

ftp_get_option()

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

?>

ftp_fput()

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

?>

ftp_fget()

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

?>

ftp_exec()

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

?>

ftp_delete()

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

?>