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

?>

ftp_close

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

?>

ftp_chmod

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

?>

ftp_chdir

It changes the current directory on a FTP server

Example

<?php

$fName = “/home/user/test.txt”;

$ftpId = ftp_connect(‘ftp.phpcodez.com’);

$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);

ftp_chdir($ftpId, ‘phpcodez’);

?>

ftp_cdup

It changes to the parent directory

Example

<?php

$fName = “/home/user/test.txt”;

$ftpId = ftp_connect(‘ftp.phpcodez.com’);

$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);

ftp_chdir($ftpId, ‘phpcodez’);

ftp_cdup($ftpId) or die(“Failed”);

  echo ftp_pwd($ftpId);

?>

ftp_alloc

It allocates space for a file to be uploaded

Example

<?php

$fName = “/home/user/test.txt”;

$ftpId = ftp_connect(‘ftp.phpcodez.com’);

$login_result = ftp_login($ftpId, ‘anonymous’, ‘user@phpcodez.com’);

ftp_alloc($ftpId, filesize($fName), $result) or die($result);

ftp_put($ftpId, ‘temfileName’, $file, FTP_BINARY);

ftp_close($ftpId);

?>