我有一个脚本连接到外部ftp服务器并下载文件夹的内容。
目前它将下载该文件夹中的所有文件。如何修改以下脚本以仅下载和处理.csv文件并忽略任何其他文件?
我的脚本是(100%有效):
$timenow=time();
$ftp_server = "ftp.domain.com";
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = "username";
$ftp_user_pass = "password";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$contents = ftp_nlist($conn_id, 'LoadsOverWB');
$targetnameprocesses ="LoadsOverWB-$timenow.csv";
$filename = $contents[0];
echo "<br><font color=blue><b>Import into LOC MySQL.....</b></font><br>";
// import file
if ((empty($filename))) { echo "$filename not existing to import.";} else {
$source = "LoadsOverWB/$filename";
$target = fopen("$filename", "w");
$conn = ftp_connect("ftp.hulamin.co.za") or die("Could not connect");
ftp_login($conn,"TransportLogistics","Qaz1234");
ftp_fget($conn,$target,$source,FTP_ASCII);
echo "file downloaded. <br>";
一如既往地感谢您的帮助,
答案 0 :(得分:1)
试试这个:
if ('.csv' == strtolower(substr($filename, -4))) { //Get the file }