PHP and FTP database connection code

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code connect directory ftp ftp_connect function function_exists local
Using PHP to connect to the FTP database code

function Dftp_connect ($ftphost, $ftpuser, $ftppass, $ftppath, $ftpport =, $ftpssl = 0, $silent = 0) {
Global $ftp;
@set_time_limit (0);

$ftphost = Wipespecial ($ftphost);
$ftpport = Intval ($ftpport);
$ftpssl = Intval ($FTPSSL);
$ftp [' timeout '] = intval ($ftp [' timeout ']);

  $func = $ftpssl && function_exists (' Ftp_ssl_connect ')? ' Ftp_ssl_connect ': ' Ftp_connect ';
 if ($func = = ' Ftp_connect ' &&!function_exists (' Ftp_connect ')) {
  if ($silent) {
   return-4;
  } else {
   errorlog (' FTP ', "ftp not keyword.", 0);
  }
 }
 if ($ftp _conn_id = @ $func ($ftphost, $ftpport,) {
  if ($ftp [' timeout '] && function_ Exists (' ftp_set_option ') {
    @ftp_set_option ($ftp _conn_id, ftp_timeout_sec, $ftp [' TIMEOUT ']);
 &NBSP}
  if (Dftp_login ($ftp _conn_id, $ftpuser, $ftppass)) {
   if ($ftp [' PASV ']) {
    DFTP_PASV ($ftp _conn_id, TRUE);
   
    if (Dftp_chdir ($ftp _conn_id, $ftppath)) {
    return $ftp _conn_id;
   } else {
    if ($silent) {
     return-3;
    } else {
     errorlog (' FTP ', "Chdir ' $ftppath ' error.", 0);
   &NBSP}
   }
  } else {
   if ($silent) {
    return-2;
   } else {
    errorlog (' FTP ', ' 530 not logged in. ', 0);
   &NBSP}
  }
 } else {
  if ($silent) {
   return-1;
  &NBSP} else {
   errorlog (' FTP ', ' couldn ' t connect to $ftphost: $ftpport. ", 0);
  }
 }
 dftp_close ($ftp _conn_id);
 return-1;
}

function Dftp_mkdir ($ftp _stream, $directory) {
$directory = Wipespecial ($directory);
Return @ftp_mkdir ($ftp _stream, $directory);
}

function Dftp_rmdir ($ftp _stream, $directory) {
$directory = Wipespecial ($directory);
Return @ftp_rmdir ($ftp _stream, $directory);
}

function Dftp_put ($ftp _stream, $remote _file, $local _file, $mode, $startpos = 0) {
$remote _file = wipespecial ($remote _file);
$local _file = wipespecial ($local _file);
$mode = Intval ($mode);
$startpos = Intval ($startpos);
Return @ftp_put ($ftp _stream, $remote _file, $local _file, $mode, $startpos);
}

function Dftp_size ($ftp _stream, $remote _file) {
$remote _file = wipespecial ($remote _file);
Return @ftp_size ($ftp _stream, $remote _file);
}

function Dftp_close ($ftp _stream) {
Return @ftp_close ($ftp _stream);
}

function Dftp_delete ($ftp _stream, $path) {
$path = Wipespecial ($path);
Return @ftp_delete ($ftp _stream, $path);
}

function Dftp_get ($ftp _stream, $local _file, $remote _file, $mode, $resumepos = 0) {
$remote _file = wipespecial ($remote _file);
$local _file = wipespecial ($local _file);
$mode = Intval ($mode);
$resumepos = Intval ($resumepos);
Return @ftp_get ($ftp _stream, $local _file, $remote _file, $mode, $resumepos);
}

function Dftp_login ($ftp _stream, $username, $password) {
$username = Wipespecial ($username);
$password = Str_replace (Array ("n", "R"), Array (","), $password);
Return @ftp_login ($ftp _stream, $username, $password);
}

function Dftp_pasv ($ftp _stream, $PASV) {
$PASV = Intval ($PASV);
Return @ftp_pasv ($ftp _stream, $PASV);
}

function Dftp_chdir ($ftp _stream, $directory) {
$directory = Wipespecial ($directory);
Return @ftp_chdir ($ftp _stream, $directory);
}

function Dftp_site ($ftp _stream, $cmd) {
$cmd = Wipespecial ($cmd);
Return @ftp_site ($ftp _stream, $cmd);
}

function Dftp_chmod ($ftp _stream, $mode, $filename) {
$mode = Intval ($mode);
$filename = Wipespecial ($filename);
if (function_exists (' Ftp_chmod ')) {
Return @ftp_chmod ($ftp _stream, $mode, $filename);
else {
Return Dftp_site ($ftp _stream, ' CHMOD '. $mode. '. $filename);
}
}

Related Article

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.