Using PHP to connect to the FTP database code
Last Update:2017-01-13
Source: Internet
Author: User
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 supported.", 0);
}
}
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;
} else {
Errorlog (' FTP ', ' 530 not logged in. ', 0);
}
}
} else {
if ($silent) {
return-1;
} 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);
}
}