1
A
回答
0
如果你已經有文件名來檢查,用filemtime
返回時間的文件的最後修改,或FALSE的失敗。時間以Unix時間戳返回,適用於date()函數。
爲了今天比較,你可以使用date('Y-m-d')
讓今天比較date('Y-m-d', filemtime($filename))
要獲得文件名,你可以使用readdir閱讀各一轉。
<?php
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
while (false !== ($filename = readdir($handle))) {
echo "$filename\n";
}
closedir($handle);
}
?>
該手冊還有一個FTP example它應該告訴你如何找到ftp文件。
因此,結合這一切,你可以得到這樣的:
<?php
// 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 "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";
}
if ($handle = opendir('/path/to/files')) {
while (false !== ($filename = readdir($handle))) {
if (date('Y-m-d') == date('Y-m-d', filemtime($filename))) {
// upload the file
$upload = ftp_put($conn_id, $destination_file, $filename, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
}
}
closedir($handle);
// close the FTP stream
ftp_close($conn_id);
?>
當然,您需要填寫虛值適當。
免責聲明:我在記事本++中鍵入了它,並沒有測試任何錯誤!
0
鏈接: http://www.php.net/manual/en/function.ftp-rawlist.php
你連接到服務器, 得到的文件列表與ftp_rawlist()
並獲得唯一的文件你通過ftp_fget()
例如要
<?php
// 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);
// get the file list for/
$rawfiles = ftp_rawlist($conn_id, '/');
foreach ($rawfiles as $rawfile) {
# parse the raw data to array
if(!empty($rawfile)) {
$info = preg_split("/[\s]+/", $rawfile, 9);
$arraypointer[] = array(
'text' => $info[8],
'isDir' => $info[0]{0} == 'd',
'size' => byteconvert($info[4]),
'chmod' => chmodnum($info[0]),
'date' => strtotime($info[6] . ' ' . $info[5] . ' ' . $info[7]),
'raw' => $info
// the 'children' attribut is automatically added if the folder contains at least one file
);
// pseudo code check the date
if($arraypointer['date'] is today)
ftp_fget(file);
}
// close the connection
ftp_close($conn_id);
// output the buffer
var_dump($buff);
?>
相關問題
- 1. 查看訂單僅限今天
- 2. SQL僅返回今天的數據
- 3. 僅在今天全日曆顯示
- 4. FTP僅更改MSBuild中的文件
- 5. Atom/RSS訂閱顯示僅今天發佈的文章
- 6. C#FTP獲取今天已添加的文件
- 7. Windows批處理文件 - 僅上傳最新文件到FTP
- 8. 要今天添加文件
- 9. 在Excel中索引僅限於今天之後的答案
- 10. 僅爲今天獲取指定記錄sql
- 11. time()with clearTime - 僅在今天上午12:00
- 12. 僅在今天的日期顯示錶格數據
- 13. 僅選擇今天(自午夜以來)的時間戳
- 14. 使用Windows批處理文件從FTP服務器下載今天的文件
- 15. 如何讓SSIS FTP任務執行FTP腳本而不是僅上傳文件?
- 16. 僅追加文件
- 17. 僅壓縮文件
- 18. 僅Corona SDK 30天嗎?
- 19. 今天
- 20. 今天
- 21. 僅grep文本文件
- 22. 創建今天的日期文件夾
- 23. 計數與今天的日期文件
- 24. 試圖從EC2訪問FTP僅支持
- 25. Ftp僅在.NET 4.0中拋出WebException
- 26. iPhone SDK - 天,今天
- 27. 怎麼辦:「今天到今天-7」?
- 28. 本地化文字「今天」
- 29. C#代碼僅用於從日曆中選擇今天的日期
- 30. 對於今天的條件
我想我誤解了你的問題。如果是這樣,請看haim的答案。 http://stackoverflow.com/questions/3396685/ftping-only-todays-files-only/3396742#3396742 – 2010-08-03 13:22:20