1. Obtain the specified version from SVN.
Command Line: SVN update svnworkpath -- username XXX -- password XXX-r head
$ Cmd= "SVN update ..."
$ Ar=Array();
$ Status= 0;
Exec($ Cmd,$ Ar,$ Status);
The returned results include the following:
A 002/ftp_upload.phpu 002/Main. phpd 002/config. php
2. processing cost path and Server Upload path:
Function svnmessage ($ remotearr, $ localarr, $ config_pg, $ config_dir) {/** local dir */For ($ CTR = 0; $ CTR <count ($ localarr) -1; $ CTR ++) {// $ localarr [$ CTR] = str_replace ($ config_flg, '', $ localarr [$ CTR]); $ istr = stripos ($ localarr [$ CTR], $ config_pg); $ localarr [$ CTR] = substr ($ localarr [$ CTR], $ istr ); $ localarr [$ CTR] = str_replace ('\', '/', $ localarr [$ CTR]);} echo "local path: <br/> \ r \ n "; for ($ CTR = 0; $ CTR <count ($ localarr)-1; $ CTR ++) {echo $ localarr [$ CTR]; echo "<br/> \ r \ n" ;}/ ** remote dir */For ($ I = 0; $ I <count ($ remotearr)-1; $ I ++) {// $ remotearr [$ I] = str_replace ($ config_pg ,'', $ remotearr [$ I]); $ imstr = stripos ($ remotearr [$ I], $ config_pg); $ remotearr [$ I] = substr ($ remotearr [$ I], $ imstr + strlen ($ config_pg); $ remotearr [$ I] = $ config_dir.str_replace ('\', '/', $ remotearr [$ I]);} echo "<br/> \ r \ n upload path: <br/> \ r \ n"; for ($ I = 0; $ I <count ($ remotearr) -1; $ I ++) {echo $ remotearr [$ I]; echo "<br/> \ r \ n ";}}
3. Connect to FTP
$ Conn = ftp_connect ($ ftp_ip) or die ("cocould not connect"); ftp_login ($ Conn, $ ftp_user, $ ftp_pass );
4. Upload time zones A, U, D, and files or folders
Function ftp_handle_one ($ Conn, $ Aud, $ localfile, $ remotefile) {echo "$ Aud, $ localfile, $ remotefile \ r \ n"; $ r = true; if ($ aud = 'D') {// the local file cannot be found and the folder cannot be determined. Try {$ r = ftp_delete ($ Conn, $ remotefile); echo "delete a file $ remotefile --> $ r \ n"; if (! $ R) {$ r = removedir ($ Conn, $ remotefile); echo "delete directory $ remotefile --> $ r \ n" ;}} catch (exception $ E) {echo 'capture exception :'. $ e-> getmessage (). "<br/> ErrorCode:". $ E-> getcode (). '<br/> \ r \ n'; echo "------ \ r \ n" ;}} else if ($ aud = 'A ') {If (is_dir ($ localfile) {$ r = ftp_mkdir ($ Conn, $ remotefile); echo "create directory $ remotefile --> $ r \ n ";} else {$ r = ftp_upload_one ($ Conn, $ localfile, $ remotefile); echo "Create File $ remotefile --> $ r \ n ";}} else if ($ aud = 'U') {If (is_dir ($ localfile) {// ftp_rmdir ($ Conn, $ remotefile );} else {$ r = ftp_upload_one ($ Conn, $ localfile, $ remotefile); echo "Update file $ remotefile --> $ r \ n ";}}}
5. recursively delete a directory
Function removedir ($ Conn, $ dirname) {$ arr = ftp_rawlist ($ Conn, $ dirname); // when a directory is created, three rows are generated by default. // array (3) {// [0] => string (7) "Total 0" // [1] => string (56) "drw-RW-1 user group 0 Sep 23 13:56. "// [2] => string (57)" drw-RW-1 user group 0 Sep 23 13:56 .. "//} If (count ($ ARR)> = 3) {for ($ I = 3; $ I <count ($ ARR); $ I ++) {$ isdir = substr ($ arr [$ I],); $ filename = substr ($ arr [$ I], 55); // obtain the file name. $ Filename = "$ dirname/$ FILENAME"; echo "$ isdir | $ FILENAME"; echo "\ r \ n"; if ($ isdir = "D ") {removedir ($ Conn, $ filename);} else {ftp_delete ($ Conn, $ filename) ;}} ftp_rmdir ($ Conn, $ dirname); Return true ;} else {return false ;}}
6. upload an object
Function ftp_upload_one ($ Conn, $ localfile, $ remotefile) {// start $ fp = fopen ($ localfile, 'R'); $ ret = ftp_nb_fput ($ Conn, $ remotefile, $ FP, ftp_binary); While ($ ret = ftp_moredata) {// Add other code to be executed echo ".... "; // continue transmission... $ ret = ftp_nb_continue ($ conn);} if ($ RET! = Ftp_finished) {echo "An error occurred while uploading the file..."; exit (1);} return true ;}
I feel that PHP supports FTP and command line very well. The script is easy to write.