php與ftp資料庫連接代碼

來源:互聯網
上載者:User
關鍵字 網路程式設計 PHP教程
使用php與ftp資料庫連接代碼

function dftp_connect($ftphost, $ftpuser, $ftppass, $ftppath, $ftpport = 21, $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) {
& nbsp;  return -4;
  } else {
   errorlog('FTP', "FTP not supported.", 0);
  }
 }< br>  if($ftp_conn_id = @$func($ftphost, $ftpport, 20)) {
  if($ftp['timeout'] && function_ exists('ftp_set_option')) {
   @ftp_set_option($ftp_conn_id, FTP_TIMEOUT_SEC, $ftp['timeout']);
  }
  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);
    }
   }
  } else {
   if($silent) {
    return -2;
  & nbsp;} else {
    errorlog('FTP', '530 Not logged in.', 0);
   }
  }< br>  } else {
  if($silent) {
   return -1;
  } else {
 &nbs p; 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);
}
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.