• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

php code to connect to remote ftp server

i am looking for php code to connect to a remote ftp server


the information I have is
hostname
portnumber (21)
username
password
0
rgb192
Asked:
rgb192
2 Solutions
 
Frederic SuneCEO, IT in MIND inc.Commented:
You have all information on PHP official manual.
Here is a quick code:
//Connect to the FTP server
$ftpstream = @ftp_connect('localhost');

//Login to the FTP server
$login = @ftp_login($ftpstream, 'user', 'secret');
if($login) {
	//We are now connected to FTP server.
}

//Close FTP connection
ftp_close($ftpstream);

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
@itinmind, when you are first testing code, you should not use '@' in front of the functions to suppress errors.  You need to see the errors to know what is wrong so you can fix it.

Here's another page with an example: http://www.php.net/manual/en/ftp.examples-basic.php  You might want to turn all error reporting on: http://us2.php.net/manual/en/function.error-reporting.php 

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

Open in new window

0
 
rgb192Author Commented:
good idea to show errors

thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now