Hi -
I am having a strange PHP issue. I have a sample script which uploads a file via PHP's FTP functions. The script is stored in a web-accessible directory on a Red Hat Linux box. When I run the script from the command line (php -f ftp_test.php), everything works perfectly...a connection is established, it logs in, uploads the file, and exits. However, when I attempt to run this same exact script from a web browser (http://www.something.com/test_files/ftp_test.php), the script fails to connect at all.
Has anyone else ever encountered this?
Below is my sample script (with server/username/pw removed for obvious security reasons).
Thanks.
<?php
// set up basic connection
$ftp_server = "some server address";
// no error handling this is just a test script
$ftp_user_name = "username";
$ftp_user_pass = "password";
$source_file = "/tmp/test_ftp_file.txt";
$destination_file = "test_ftp_file.txt";
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, false);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>