Tag Archives: FTP

ftp_quit()

Its an alias ftp_close() and  closes ftp conection

Example

<?php

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

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

echo ftp_pwd($ftpId)

ftp_quit($ftpId);

?>

ftp_pwd()

It  returns the current directory name

Example

<?php

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

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

echo ftp_pwd($ftpId)

ftp_close($ftpId);

?>

ftp_put()

It uploads a file to the FTP server

Example

<?php

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

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

ftp_put($ftpId, $rFile, $lFile, FTP_ASCII) or die(“Failed”);

ftp_close($ftpId);

?>

ftp_pasv()

It turns passive mode on or off

Example

<?php

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

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

ftp_pasv($conn_id, false);

ftp_close($ftpId);

?>

ftp_nlist()

It returns a list of files in the given directory

Example

<?php

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

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

$data = ftp_nlist($ftpId, “.”);

ftp_close($ftpId);

?>

 

ftp_nb_put()

It stores a file on the FTP server

Example

<?php

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

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

$ret = ftp_nb_put($ftpId, “serverFile”, “localfile”, FTP_BINARY);

while ($dest == FTP_MOREDATA) {

  $dest = ftp_nb_continue($ftpId);

}

  ftp_close($ftpId);

  fclose($fp);

?>

ftp_nb_get()

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

?>

ftp_nb_fput()

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

?>

ftp_nb_fget()

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

?>

ftp_nb_continue()

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

?>