Php sftp usage tutorial. Sftp in php use tutorial config $ config;} ftp connection publicfunctionconnect () {return $ this-connftp_connect ($ this-config [host], $ this-config [port]);} tutorial on sftp in php for data transmission
Config = $ config;} // ftp connection public function connect () {return $ this-> conn = ftp_connect ($ this-> config ['host'], $ this-> config ['port']);} // transmission data transport layer protocol, get data true or false public function download ($ remote, $ local, $ mode = 'auto') {return $ result = @ ftp_get ($ this-> conn, $ localpath, $ remotepath, $ mode);} // transport data transport layer protocol, upload data true or false public function upload ($ remote, $ local, $ mode = 'auto') {return $ res Ult = @ ftp_put ($ this-> conn, $ localpath, $ remotepath, $ mode);} // delete the file public function remove ($ remote) {return $ result = @ ftp_delete ($ this-> conn_id, $ file) ;}// use $ config = array ('hostname' => 'localhost ', 'username' => 'root', 'password' => 'root', 'port' => 21); $ ftp = new Ftp (); $ ftp-> connect ($ config); $ ftp-> upload ('ftp _ err. log', 'ftp _ upload. log'); $ ftp-> download ('ftp _ upload. log', 'ftp _ download. l Og ');/* write an ssh-Based ftp class based on the preceding three protocols. we know there are two authentication methods: public key and password. (1) login with password (2) password-free login, that is, login with the public key */class sftp {// The initial configuration is NULLprivate $ config = NULL; // The connection is NULL private $ conn = NULL; // whether to use the key to log on to private $ use_pubkey_file = false; // initialize public function init ($ config) {$ this-> config = $ config;} // connect to ssh in two ways (1) use the password // (2) use the key public function connect () {$ methods ['hostkey'] = $ use_pubkey_file? 'Ssh-rsa ': []; $ con = ssh2_connect ($ this-> config ['host'], $ this-> config ['port'], $ methods ); // (1) if ($ use_pubkey_file) {// user authentication protocol $ rc = ssh2_auth_pubkey_file ($ conn, $ this-> config ['user'], $ this-> config ['pubkey _ file'], $ this-> config ['privkey _ file'], $ this-> config ['passphrase ']); // (2) use the login username and login password} else {$ rc = ssh2_auth_password ($ conn, $ this-> conf _ ['user'], $ this-> conf _ ['passwd']);} return $ rc;} // transfer data transport layer protocol to obtain the public function download ($ remote, $ local) {return ssh2_scp_recv ($ this-> conn _, $ remote, $ local);} // transfer data transport layer protocol, written to the ftp server data public function upload ($ remote, $ local, $ file_mode = 0664) {return ssh2_scp_send ($ this-> conn _, $ local, $ remote, $ file_mode );} // delete the file public function remove ($ remote) {$ sftp = ssh2_sftp ($ this-> conn _); $ rc = false; if (is_dir (ssh2.sftp: // {$ sftp}/{$ remote}) {$ rc = false; // delete a folder through ssh $ rc = ssh2_sftp_rmdir ($ sftp, $ remote );} else {// delete the file $ rc = ssh2_sftp_unlink ($ sftp, $ remote);} return $ rc ;}$ config = [host => 192.168.1.1, // ftp address user => ***, port => 22, pubkey_path =>/root /. ssh/id_rsa.pub, // public key storage address privkey_path =>/root /. ssh/id_rsa, // private key storage address]; $ handle = new SftpAccess (); $ handle-> init ($ config ); $ rc = $ handle-> connect (); $ handle-> getData (remote, $ local );/*
Sftp in http://www.bkjia.com/PHPjc/962645.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/962645.htmlTechArticlephp use tutorial config = $ config;} // ftp connection public function connect () {return $ this-conn = ftp_connect ($ this-config [host], $ this-config [port]);} // transfer data transmission...