Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp_connect () Fatal error??

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
using the following code give me: Fatal error: Call to undefined function: ftp_connect() in /usr/local/apache/htdocs/myfolder/ftp.php on line 6
when i change it to $conn_id = @ftp_connect($ftp_server); as i read in some tutorials I get a blank page, thank you for any help.

<?php
$ftp_server = &quot;192.168.0.1&quot;;
$ftp_user_name = &quot;myusername&quot;;
$ftp_user_pass = &quot;mypassword&quot;;
// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
echo &quot;FTP connection has failed!&quot;;
echo &quot;Attempted to connect to $ftp_server for user $ftp_user_name&quot;;
die;
} else {
echo &quot;Connected to $ftp_server, for user $ftp_user_name&quot;;
}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status
if (!$upload) {
echo &quot;FTP upload has failed!&quot;;
} else {
echo &quot;Uploaded $source_file to $ftp_server as $destination_file&quot;;
}

// close the FTP stream
ftp_close($conn_id);
?>
 
Number one piece of advice. Do not prepend a function call with the &quot;@&quot;-symbol in a development environment.

Prepending the &quot;@&quot;-symbol turns off reporting of certain classes of warning messages. These are messages you want to receive during development.


If you are getting an &quot;undefined function&quot; error message when invoking a function, then it is likely that function was not activated when PHP was compiled.

In particular, PHP does not turn on support for FTP unless the compilation configuration option &quot;--enable-ftp&quot; is used.

There is one quick way to check. Create a PHP script which reads:

<?php
phpinfo();
?>

Then from your web browser, call that script. If you do not see &quot;--enable-ftp&quot; in the section titled &quot;Configuration Command&quot;, and you do not have a sub-section with a heading &quot;ftp&quot;, then support for FTP was not compiled into that installation of PHP.

If you can, reconfigure and recompile using the &quot;--enable-ftp&quot; switch as well as all the switches used in the original compile. This information is available at ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top