I have a script. It is an ftp script.
[LIST=1][*]
It goes out to a server and finds me two files that I need.
Downloads these files
Unzips these two files
Number 3 I am having issues with. This is a linux server, and for some reason I can’t use the simple shell_exec functions to do this. It also does not throw any errors.
Any ideas ya’ll? I am attaching a zip file for troubleshooting purposes.
MLSRetireveBeta.php
[code=php]
<?php
ini_set(“display_errors”, “1”);
error_reporting(E_ALL);
// set up basic connection
$ftp_server = “somedomain.com”;
$conn_id = ftp_connect($ftp_server);
// login with username and password
if ((!$conn_id) )
{
print “FTP connection has Failed!”;
exit;
}
else
{
$ftp_user_name = “anonymous”;
$ftp_user_pass = “[email protected]”;
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
}
//Turn passive mode on
ftp_pasv($conn_id, true);
//Removed so it won’t die.
if(!$login_result)
{
print “<b>Login has Failed! “.$ftp_server.” for user “.$ftp_user_name.”.</b><br/>”;
}
else
{
print “<br/>Connected to: <em>”.$ftp_server.”</em>”;
//$good would be true if I am able to navigate to folder, but it is false indicating it cannot navigate to directory
$good = ftp_chdir($conn_id, ‘/DataLinkOutput/ERI/ERI_1000001334’);
// print the current direwctory out, results in nothing
print “<br/>Current directory: <em>” . ftp_pwd($conn_id) . “</em>”;
//Get the list of files
$arrDirContents = ftp_nlist($conn_id, ‘.’);
//Sort it
natcasesort($arrDirContents);
//Loop through to find the ones I want
foreach($arrDirContents as $x)
{
//Only residential and commercial files
if(strpos($x,”_RES_”) > 0 || strpos($x,”_COM_”) > 0 )
{
//Only zips
if(strpos($x,”.zip”) > 0 )
{
//only MLS Fulls
if(strpos(” “.$x,”MF”) > 0 )
{
//For Residential
if(strpos($x,”_RES_”) > 0 )
{
$ResidentialFileName = $x;
}
//For Commercial
else
{
$BusinessFileName = $x;
}
}
}
}
}
//Check to see if we have ourselves some file names
if($ResidentialFileName != “” && $BusinessFileName != “” )
{
print(“<br/><br/>Found residential file: <i>” . $ResidentialFileName.”</i>”);
print(“<br/>Found commercial file: <i>” . $BusinessFileName.”</i>”);
//Download
if(ftp_get($conn_id, $ResidentialFileName, $ResidentialFileName, FTP_BINARY))
print(“<br/><br/>Downloaded residential file: <i>” . $ResidentialFileName.”</i>”);
if(ftp_get($conn_id, $BusinessFileName, $BusinessFileName, FTP_BINARY))
print(“<br/>Downloaded commercial file: <i>” . $BusinessFileName.”</i>”);
//Unzip
if(shell_exec(‘unzip -P ERIE $ResidentialFileName’))
print(“Unzipped residential file: <i>” . $ResidentialFileName.”</i>”);
if(shell_exec(‘unzip -P ERIE $BusinessFileName’))
print(“Unzipped commercial file: <i>” . $BusinessFileName.”</i>”);
}
else
{
if($ResidentialFileName == “”)
print “<br/>Residential file missing”;
if($BusinessFileName == “” )
print “<br/>Business file missing”;
}
}
ftp_close($conn_id);
?>
[upl-file uuid=ca01d644-2afe-489d-9711-fb01b52f6247 size=34kB]MF20100713_030456_COM_1.zip