File Transfer Protocol (FTP) is protocol that transfers files between computers. It’s a client-server communication. FTP clients do nothing but transfer files between your computer and a remote server. Examples include FileZilla, Fetch (Mac), and gFTP (Linux). Similarly, FTP server host files on its disk and whenever some client connect to it, server allows downloading, edit, upload and view of the documents depending upon the permissions of the client.

Before you connect, you need to know at least:

  1. Host name of the server such as Particularly when connecting to server hosting your website
  2. Protocol the server supports (FTP, SFTP etc.)
  3. Account username
  4. Account password
//log in.
if(!ftp_login($ftp, "anonymous", ""))
	print("Unable to login!\n");
print("Logged In.\n");
//print system type
print("System Type: " . ftp_systype($ftp) . "\n");

//make sure passive mode is off
ftp_pasv($ftp, FALSE);

//get working directory
print("Working Directory: " . ftp_pwd($ftp) . "\n");

//get files in raw format
print("Raw List:\n");
foreach(ftp_rawlist($ftp, ".") as $line)

//move to pub directory
if(!ftp_chdir($ftp, "pub"))
	print("Unable to go to the pub directory!\n");

print("Moved to pub directory.\n");

//get a list of files
foreach(ftp_nlist($ftp, ".") as $filename)

//return to root directory
	print("Failed to move up a directory!\n");

//close connection
Tagged with: PHPProgrammingSource Code

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.