douxing5199
2017-03-27 11:32
浏览 107
已采纳

在PHP中仅从FTP服务器下载新图像

I made a little script which allows me to download images from FTP server. But, the thing is, whenever I execute the script, ALL images are downloaded. Is there any way to rewrite the code so that it only downloads new images?

My script looks like this:

$ftp_server = "my_server_ip";
$ftp_user = "my_user_name";
$ftp_pass = "my_password";
$DIR="my_path_to_images_folder";

$conn = ftp_connect($ftp_server);
if(!$conn)
{
    exit("Can not connect to server: $ftp_server
");
}

if(!ftp_login($conn,$ftp_user,$ftp_pass))
{
    ftp_quit($conn);
    exit("Can't login
");
}

ftp_chdir($conn,$DIR);

$files = ftp_nlist($conn,'.');
for($i=0;$i<count($files);$i++)
{
    if(!ftp_get($conn,$files[$i],$files[$i],FTP_BINARY))
    {
        echo "Can't download {$files[$i]}
";
    }
    else
    {
        echo "Successfully transferred images!";
    }
}

ftp_quit($conn);

Thank you.

图片转代码服务由CSDN问答提供 功能建议

我制作了一个小脚本,允许我从FTP服务器下载图像。 但是,问题是,每当我执行脚本时,都会下载所有图像。 有没有办法重写代码,以便它只下载新的图像? </ p>

我的脚本如下所示:</ p>

  $ ftp_server =“my_server_ip”; 
 $ ftp_user =“my_user_name”; 
 $  ftp_pass =“my_password”; 
 $ DIR =“my_path_to_images_folder”; 
 
 $ conn = ftp_connect($ ftp_server); 
if(!$ conn)
 {
 exit(“无法连接到服务器:$  ftp_server 
“); 
} 
 
if(!ftp_login($ conn,$ ftp_user,$ ftp_pass))
 {
 ftp_quit($ conn); 
 exit(”无法登录
“  ); 
} 
 
 
ftp_chdir($ conn,$ DIR); 
 
 $ files = ftp_nlist($ conn,'。'); 
for($ i = 0; $ i&lt; count($ files)  ; $ i ++)
 {
 if if(!ftp_get($ conn,$ files [$ i],$ files [$ i],FTP_BINARY))
 {
 echo“无法下载{$ files [$  i]} 
“; 
} 
 
 
 
 
 
 
 
 
 
 
 
 \ {
 
 
 
 
 
 
 
 
 
 
 
 
呼叫”成功传输图像!  > 
 
 

谢谢。</ p> </ div>

3条回答 默认 最新

相关推荐 更多相似问题