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) { 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 ftpupload($source, $attach) { global $authkey, $ftp; $ftp['pwd'] = isset($ftp['pwd']) ? $ftp['pwd'] : FALSE; $dest = $attach['attachment']; if ($ftp['on'] && (!$ftp['allowedexts'] && !$ftp['disallowedexts'] || $ftp['allowedexts'] && in_array($attach['ext'], explode("\n", strtolower($ftp['allowedexts']))) || $ftp['disallowedexts'] && !in_array($attach['ext'], explode("\n", strtolower($ftp['disallowedexts'])))) && (!$ftp['minsize'] || $attach['size'] >= $ftp['minsize'] * 1024)) { require_once DISCUZ_ROOT . './include/ftp.func.php'; if (!$ftp['connid']) { if (!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) { if ($ftp['mirror'] == 1) { ftpupload_error($source, $attach); } else { return 0; } } $ftp['pwd'] = FALSE; } $tmp = explode('/', $dest); if (count($tmp) > 1) { if (!$ftp['pwd'] && !dftp_chdir($ftp['connid'], $tmp[0])) { if (!dftp_mkdir($ftp['connid'], $tmp[0])) { errorlog('FTP', "Mkdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0); if ($ftp['mirror'] == 1) { ftpupload_error($source, $attach); } else { return 0; } } if (!function_exists('ftp_chmod') || !dftp_chmod($ftp['connid'], 0777, $tmp[0])) { dftp_site($ftp['connid'], "'CHMOD 0777 {$tmp['0']}'"); } if (!dftp_chdir($ftp['connid'], $tmp[0])) { errorlog('FTP', "Chdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0); if ($ftp['mirror'] == 1) { ftpupload_error($source, $attach); } else { return 0; } } dftp_put($ftp['connid'], 'index.htm', $GLOBALS['attachdir'] . '/index.htm', FTP_BINARY); } $dest = $tmp[1]; $ftp['pwd'] = TRUE; } if (dftp_put($ftp['connid'], $dest, $source, FTP_BINARY)) { if ($attach['thumb']) { if (dftp_put($ftp['connid'], $dest . '.thumb.jpg', $source . '.thumb.jpg', FTP_BINARY)) { if ($ftp['mirror'] != 2) { @unlink($source); @unlink($source . '.thumb.jpg'); } return 1; } else { dftp_delete($ftp['connid'], $dest); } } else { if ($ftp['mirror'] != 2) { @unlink($source); } return 1; } } errorlog('FTP', "Upload '{$source}' error.", 0); $ftp['mirror'] == 1 && ftpupload_error($source, $attach); } return 0; }
function ftpupload($source, $dest, $havethumb = 0) { global $authkey, $ftp; if ($ftp['on']) { require_once DISCUZ_ROOT . './include/ftp.func.php'; if (!$ftp['connid']) { if (!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) { return 0; } $ftp['pwd'] = FALSE; } $tmp = explode('/', $dest); if (count($tmp) > 1) { if (!$ftp['pwd'] && !dftp_chdir($ftp['connid'], $tmp[0])) { if (!dftp_mkdir($ftp['connid'], $tmp[0])) { errorlog('FTP', "Mkdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0); return 0; } if (!function_exists('ftp_chmod') || !dftp_chmod($ftp['connid'], 0777, $tmp[0])) { dftp_site($ftp['connid'], "'CHMOD 0777 {$tmp['0']}'"); } if (!dftp_chdir($ftp['connid'], $tmp[0])) { errorlog('FTP', "Chdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0); return 0; } dftp_put($ftp['connid'], 'index.htm', $GLOBALS['attachdir'] . '/index.htm', FTP_BINARY); } $dest = $tmp[1]; $ftp['pwd'] = TRUE; } if (dftp_put($ftp['connid'], $dest, $source, FTP_BINARY)) { if ($havethumb) { if (dftp_put($ftp['connid'], $dest . '.thumb.jpg', $source . '.thumb.jpg', FTP_BINARY)) { @unlink($source); @unlink($source . '.thumb.jpg'); return 1; } else { dftp_delete($ftp['connid'], $dest); } } else { @unlink($source); return 1; } } errorlog('FTP', "Upload '{$source}' error.", 0); } return 0; }