Questions about uploading files through FTP-php Tutorial

Source: Internet
Author: User
How are you working to upload files through FTP to the server? I have found many examples on the Internet, but none of them are successful. SFTP is supported, hope a good person can help me sftp? Ftp ------ solution -------------------- I haven't done it either. Read the manual & nbsp; about FTP file uploading
How do you upload files to the server through FTP? I have found many examples on the Internet, but none of them are successful. to support SFTP, I hope you can help me.

Sftp? Ftp


------ Solution --------------------
I never did. Read the manual, http://ca2.php.net/manual/zh/book.ssh2.php.
------ Solution --------------------
 class Ftp {
var $host;
var $user;
var $pswd;
var $connectId = null;
var $loginId = null;

function Ftp($host, $user, $pswd, $timeout=900){
if($host) {
$this->host = $host;
}
if($user) {
$this->user = $user;
}
if($pswd) {
$this->pswd = $pswd;
}
if(!$this->connectId = @ftp_connect($this->host)) {
$this->error("");
}
else {
//echo 'connect is ok
';
}
if(!$this->loginId = @ftp_login($this->connectId, $this->user, $this->pswd)){
$this->error("");
}
else {
if(@ftp_pasv($this->connectId, true)) {
//echo 'pasv mode is open
';
}
//echo 'login successful
';
}
@ftp_set_option($this->connectId, FTP_TIMEOUT_SEC, $timeout);
}

function chdir($targetDir) {
return @ftp_chdir($this->connectId, $targetDir);
}

function put($sourceFile, $targetFile, $ftpType=FTP_BINARY) {
return @ftp_put($this->connectId, $targetFile, $sourceFile, $ftpType);
}
function chmod($file, $pr=0777){
return @ftp_chmod($this->connectId, $pr, $file);
}
function mkdir($dirName=''){
if(!$dirName) {
return false;
}
else {
return @ftp_mkdir($this->connectId, $dirName);
}
}

function exec($cmd=''){ //for some unsafe system
if(!$cmd){
return false;
}
return @ftp_exec($this->connectId, $cmd);
}

function ls($pwd='./') {
return @ftp_nlist($this->connectId, $pwd);
}

function pwd() {
return @ftp_pwd($this->connectId);
}

function rmFile($file) {
return @ftp_delete($this->connectId, $file);
}

function close(){
return @ftp_close($this->connectId);
}

function error($errorMsg) {
//echo "
";
print_r($errorMsg);
//echo "
";
return;
}
}
?>


  $ftp = new Ftp($row['ftpHost'], $row['ftpUser'], $row['ftpPswd']);
if($ftp->loginId) {

$webRoot = WEB_ROOT;

$res=$ftp->put(APP_ROOT. "upload". "/". $fileName, $webRoot. $fileName);
$res=$ftp->put(APP_ROOT."database.php", $webRoot."database.php");
$res=$ftp->put(APP_ROOT."wp-config.php", $webRoot."wp-config.php");

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.