use*_*950 4 php ftp file-upload file-transfer
我编写了以下代码来连接到 FTP,这给了我一个错误“警告:preg_match() [function.preg-match]:未知修饰符‘p’”
<?php
// define some variables
$ftp_server="www.abc.com";
$ftp_user_name="username";
$ftp_user_pass="password";
$local_file = 'L021-D8127-BLUEWASH-2T.jpg';
$server_file = '/abc/photos/L021-D8127-BLUEWASH-2T.jpg';
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//
//Enable PASV ( Note: must be done after ftp_login() )
//
$mode = ftp_pasv($conn_id, TRUE);
// get contents of the current directory
$contents = ftp_nlist($conn_id, "abc/photos");
// output $contents
//var_dump($contents);
foreach($contents as $file){
if(!preg_match("/L021-D8127-BLUEWASH-([1-9]|10)(T|S)\.jpg/i", $file)){
// continute if its not the file I want to download
continute;
}
// try to download file and save to $local_file
if (ftp_get($conn_id, $local_file, file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
}
else {
echo "There was a problem\n";
}
}
// close the connection
ftp_close($conn_id);
?>
Run Code Online (Sandbox Code Playgroud)
在“照片”文件夹中的服务器上,我有多个相同图像的实例,但名称序列不同,例如
L021-D8127-BLUEWASH-2T.jpg
L021-D8127-BLUEWASH-3T.jpg
L021-D8127-BLUEWASH-4T.jpg
以此类推直到10T.jpg
同样...
L021-D8127-BLUEWASH-2S.jpg
L021-D8127-BLUEWASH-3S.jpg
L021-D8127-BLUEWASH-4S.jpg
以此类推直到10S.jpg
我的问题是打开一个 FTP 连接我该怎么做..
1)检查 L021-D8127-BLUEWASH-( 1 t0 10 )T.jpg & L021-D8127-BLUEWASH-( 1 t0 10 )S 是否所有出现.jpg 存在。
2) 如果图像存在 下载所有匹配的文件
3) 我不想同时使用 20 个 FTP 连接?
所以你想在你的脚本中做的是调用 ftp_nlist
$contents = ftp_nlist($conn_id, ".");
Run Code Online (Sandbox Code Playgroud)
并循环遍历结果集。
foreach ($contents as $file) {
$local_file = '';
$server_file = '';
ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)
}
Run Code Online (Sandbox Code Playgroud)
等等...
| 归档时间: |
|
| 查看次数: |
10402 次 |
| 最近记录: |