PHP writes the FTP class

Source: Internet
Author: User
Tags date anonymous echo date ftp ftp connection connect require

FTP Class (myftp.php)


<?php

Class Myftp {

var $connector;
var $getback;

Function Connect ($ftp _server, $uname, $passwd) {
Baut Grundlegende FTP Connection auf
$this->connector = @ftp_connect ($ftp _server);
$this->login_result = @ftp_login ($this->connector, "$uname", "$passwd");
if (! $this->connector) ││ (! $this->login_result))
{
echo "FTP Connection has failed! n ";
echo "Attempted to connect to $ftp _server for user $uname n";
Die
} else {
echo "Connected to $ftp _server, for user $uname n";
}
}

function Lastmodtime ($value) {
$getback = Ftp_mdtm ($this->connector, $value);
return $getback;
}

function Changedir ($targetdir) {
$getback = Ftp_chdir ($this->connector, $targetdir);
return $getback;
}
function Getdir () {
$getback = ftp_pwd ($this->connector);
return $getback;
}

function Get_file_list ($directory) {
$getback = Ftp_nlist ($this->connector, $directory);
return $getback;
}

function Get_file ($file _to_get, $mode, $mode 2) {
$realfile = basename ($file _to_get);
$filename = $realfile;

$checkdir = @ $this->changedir ($realfile);
if ($checkdir = = TRUE) {
Ftp_cdup ($this->connector);
echo "N[dir] $realfile";
}else{
echo "..... ". $realfile. " n ";
$getback = Ftp_get ($this->connector, $filename, $realfile, $mode);
if ($mode 2) {
$delstatus = Ftp_delete ($this->connector, $file _to_get);
if ($delstatus = = TRUE) {
echo "File $realfile on $host deleted n";
}
}
}
return $getback;
}

function mode ($pasvmode) {
$result = FTP_PASV ($this->connector, $pasvmode);
}

function Ftp_bye () {
Ftp_quit ($this->connector);
return $getback;
}
}

?>

<?php
Flush ();

$ftp _ini_datei = $argv [1];

Require ('./ftp_class.php ');
Require ($ftp _ini_datei);

echo "Ncronjob started:";
echo Date ("D.m.y-h:i:s");
echo "n";

$newftp = new Myftp;

if (! $anonymous) {
$result = $newftp->connect ($host, $user, $password);
}else{
$result = $newftp->connect ($host, "Anonymous", "mymail@somewhere.com");
}

if (! $result) {
$mydir = $newftp->changedir ($remote _dir);
$mydir = $newftp->getdir ();
$merkold _dir = GETCWD ();
ChDir ($local _dir);
$mylist = Array ();
$mylist = $newftp->get_file_list ($mydir);



for ($i =0; $i < sizeof ($mylist); $i + +)
{
$result = $newftp->get_file ($mylist [$i], $mymode, $delete);
}

$result = $newftp->ftp_bye ();

}else{

echo "----------------------------------n";
echo "No connection established:(n";
echo "----------------------------------n";

}

echo "Nncronjob stopped:";
echo Date ("D.m.y-h:i:s");
echo "n";
?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.