ftp ทุกไฟล์จาก host นึง ไปยัง host นึง ผ่าน php ทำไงครับ

เริ่มโดย Nemesis, 03 ตุลาคม 2007, 10:28:52

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

Nemesis

ตามหัวข้อเลยครับ แบบว่า ผมลองทำแล้วรัน สักพัก browser มันก็หยุดไป.... อัพโหลดไปแค่ ไฟล์เดียว ไม่ก็สองไฟล์ก็หยด

<?php
@set_time_limit(0);
function 
readfilelist($dirname) {
$dir opendir($dirname);
$i=0;
$list=array();
while(false !== ($file readdir($dir))){
if($file != "." && $file != ".." && $file != "Thumbs.db" && is_dir($file)!=true && $file!="index.php"){
$list[$i++]=$file;
}
}
closedir($dir);
return $list;
}

$filelist readfilelist(".");

foreach(
$filelist as $filename) { 
echo 
$filename."<br>";
$ftp_server "xxx.com";
$ftp_user_name "username"// Username
$ftp_user_pass "pass";   // Password
// 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";
    }

// upload the file
$upload ftp_put($conn_id$filename$filenameFTP_BINARY);

// check upload status
if (!$upload) {
        echo 
"FTP upload has failed!";
    } else {
        echo 
"Uploaded $source_file to $ftp_server as $destination_file";
    }

// close the FTP stream
ftp_close($conn_id);

}
?>



อยากให้มันรันตลอด อัพไปทีละไฟล์จนกว่าจะหมดในโฟลเดอร์ (โฟลเดอร์เดียวนะครับ) น่ะครับ ใครพอรู้ช่วยหน่อย  :-*
[direct=http://kiwifairy.com]ชุดราตรีคนอ้วน สาวอวบ พร้อมส่ง[/direct]

golf98765

ใช้ net2ftp สิครับ

ติดตั้งง่าย ทำงานก็ง่าย เหมือน panel ของ dreamhost อ่ะครับ
:)

Nemesis

อ้างถึงจาก: golf98765 ใน 03 ตุลาคม 2007, 10:36:38
ใช้ net2ftp สิครับ

ติดตั้งง่าย ทำงานก็ง่าย เหมือน panel ของ dreamhost อ่ะครับ
:)

แล้วมัน ftp จาก ไฟล์ในโฮส ไปที่อื่นได้ใช่ป่ะคับ ถ้าได้ก็... เชเลย

อ่า ลองอ่าน feature หล่ะ ใช้ได้

ขอบคุณคร๊าบ
[direct=http://kiwifairy.com]ชุดราตรีคนอ้วน สาวอวบ พร้อมส่ง[/direct]

Nemesis

ลองใช้ดูแล้วครับ ใช้ไม่ได้อะครับ เวลาก๊อปไปอีก ftp มัน error ตลอดเลย ลองไฟล์เล็กๆ ไม่มี error แต่ไปดู ftp ปลายทาง ไม่มีไฟล์ใดๆ ไปที่โน่นเลย ลองใช้ตัวหลักที่เว็บเค้าเลยก็ใช้ไม่ได้เหมือนกัน... แล้วผมจะทำไงต่อหล่ะนิ  ???
[direct=http://kiwifairy.com]ชุดราตรีคนอ้วน สาวอวบ พร้อมส่ง[/direct]

Tee++;

ใช้ cURL

<?php
function download_ftp_multiple_file($server$username$password$directory) {
    print 
"$server<br>";
    print 
"$username<br>";
    print 
"$password<br>";
    print 
"$directory<br>";

    
$location "ftp://".$server."/".$directory."/";
    print 
"$location<br>";

    
$curl curl_init();
    
curl_setopt($curlCURLOPT_URL$location);
    
curl_setopt($curlCURLOPT_FTPLISTONLY1);
    
curl_setopt($curlCURLOPT_USERPWD"$username:$password");
    
curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    
$return trim(curl_exec($curl));
    
$files explode("\n"$return);
    
curl_close ($curl);

    
$totalfiles count($files);
    print 
"$totalfiles<br>";

    for (
$x=0$x<$totalfiles$x++) {
        print 
"X = $x<br>";
         
        
$fetchfile trim($files[$x]);
        print 
"$fetchfile<br>";
        print 
"$location$fetchfile<br>";
        
$file fopen($fetchfile"wb");

        
$curl curl_init();
        
curl_setopt($curlCURLOPT_URL"$location$fetchfile");
        
curl_setopt($curlCURLOPT_USERPWD"$username:$password");
        
curl_setopt($curlCURLOPT_FILE$file);
        
curl_exec($curl);
        
curl_close ($curl);   
        
fclose($file);
    }

}

download_ftp_multiple_file('202.111.111.111''user''pwd''httpdocs/directory');
?>
[direct=http://laravel.in.th]Laravel in Thai[/direct]
[direct=http://jquerytips.com]jQueryTips by Tee++;[/direct]
[direct=https://www.facebook.com/jQueryTips]jQueryTips Page[/direct]
[direct=https://www.facebook.com/Laravel.in.th]Laravel in Thai Page[/direct]
[direct=https://twitter.com/Teepluss]Teepluss's Twitter[/direct]


Nemesis

[direct=http://kiwifairy.com]ชุดราตรีคนอ้วน สาวอวบ พร้อมส่ง[/direct]