![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
有哪位前辈用PHP写过FTP方面的程序?
我用程序ftp下到服务器上的文件总是不完整,少了很多字节数。
---------------------------------------------------------------------------
ftp.class.php
[php]
<?
class Friend_FTP {
var $FTP_HOST; //FTP 主机名
var $FTP_PORT = 21; //FTP 端口号
var $FTP_USER; //FTP 用户名
var $FTP_PWD; //FTP用户密码
var $FTP_DIR; //FTP 目的目录
var $LOCAL_DIR; //FTP 源目录
function Friend_FTP($FTP_HOST,$FTP_PORT,$FTP_USER,$FTP_PWD,$FTP_DIR,$LOCAL_DIR){
$this ->FTP_HOST = $FTP_HOST;
$this ->FTP_PORT = $FTP_PORT;
$this ->FTP_USER = $FTP_USER;
$this ->FTP_PWD = $FTP_PWD;
$this ->FTP_DIR = $FTP_DIR;
$this ->LOCAL_DIR = $LOCAL_DIR;
}
function Friend_FTP_UP(){
$handle=opendir($this ->LOCAL_DIR);
while (false !== ($file = @readdir($handle)))
{
if(is_file($this ->LOCAL_DIR.$file))
{
$f[]=$file;
}
}
closedir($handle);
sort($f);
$mode = FTP_BINARY; // or FTP_ASCII
$conn_id = ftp_connect($this ->FTP_HOST, $this ->FTP_PORT);
ftp_login($conn_id, $this ->FTP_USER, $this ->FTP_PWD);
ftp_pwd($conn_id);
ftp_chdir($conn_id,$this ->FTP_DIR);
foreach($f as $files)
{
$from = fopen($this ->LOCAL_DIR.$files,"r");
ftp_fput($conn_id, $files, $from, $mode);
}
ftp_quit($conn_id);
}
}
?>
[/php]
-------------------------------------------------------------------------------------
ftp.up.php
[php]
<?php
include ("ftp.class.php");
$FTP_HOST = "127.0.0.1";
$FTP_PORT = 21;
$FTP_USER = "test";
$FTP_PWD = "123";
$LOCAL_DIR = "/test/";
$FTP_DIR = "/";
$a = new Friend_FTP($FTP_HOST,$FTP_PORT,$FTP_USER,$FTP_PWD,$FTP_DIR,$LOCAL_DIR);
$a ->Friend_FTP_UP();
?>
[/php]

