For ftp in web mode, it is recommended to join the essence area.

Source: Internet
Author: User
Tags ftp login ftp client
? Php * $ Id: ftp. php, v2.22002031223: 21: 28 paulsExp $ ** Thissoftwarecamefrominebria.com ** Copyright (c) 2000PaulSouthworth. Allrightsreserved. mismatch, withorwithoutmodificatio
/* $ Id: ftp. php, v 2.2 2002/03/12 23:21:28 pauls Exp $ */

/* This software came from http://inebria.com /*/

/* Copyright (c) 2000
Paul Southworth. All rights reserved.

Redistribution and use in source and binary forms, with or
Modification, are permitted provided that the following conditions
Are met:
1. Redistributions of source code must retain the above copyright
Notice, this list of conditions and the following disclawing.
2. Redistributions in binary form must reproduce the above copyright
Notice, this list of conditions and the following disclawing in
Documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote
Products derived from this software without specific prior
Written permission.

This software is provided by the author ''as is 'AND ANY EXPRESS
Or implied warranties, INCLUDING, but not limited to, THE IMPLIED
Warranties of merchantability and fitness for a particle PURPOSE
Are disclaimed. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, but not limited to, PROCUREMENT OF SUBSTITUTE
Goods or services; loss of use, DATA, or profits; OR BUSINESS
INTERRUPTION) however caused and on any theory of liability,
Whether in contract, strict liability, or tort (INCLUDING NEGLIGENCE
Or otherwise) arising in any way out of the use of this software,
Even if advised of the possibility of such damage .*/

/* Configuration Options */

$ Phpftp_host = "localhost ";
$ Phpftp_version = "2.2 ";

/* Comment this out if you don't want the version footer */

$ Show_version_footer = 1;

/* How large a file will you accept? You may also need to edit your
Php. ini file and change upload_max_filesize appropriately */

$ Max_file_size = "1000000 ";

/* The temporary directory $ phpftp_tmpdir must exist and be writable
By your web server.
Hint: mkdir/var/tmp/xfers & chmod 1777/var/tmp/xfers */

$ Phpftp_tmpdir = "/var/tmp/xfers ";

/* $ Use_mime_lookup
Turning this on creates a dependency upon
Http://www.inebria.com/mime_lookup/ MIME type lookup library.
Setting this variable to "1" enables it. "0" disables.
If you turn it on, put the mime_lookup.php file in the same directory
As ftp. php and uncomment the 'include ("mime_lookup.php"); 'statement .*/

$ Use_mime_lookup = "0 ";
/* Include ("mime_lookup.php ");*/

/* We enclose the top and bottom in functions because sometimes
We might not send them (ie, in a file-download situation )*/

Function phpftp_top (){
Global $ phpftp_version;
?>



Php ftp Client <? Php echo $ phpftp_version;?>


}

Function phpftp_bottom (){
Global $ phpftp_version;
Global $ show_version_footer;
?>

If (isset ($ show_version_footer )){
?>

This is PHP FTP
Version


}
?>


}

/* This is the form used for initially collecting username/passwd */

Function phpftp_login (){
Phpftp_top ();
?>




Phpftp_bottom ();
}

/* This function does not return TRUE/FALSE-it returns the value
$ Ftp, the current FTP stream .*/

Function phpftp_connect ($ phpftp_user, $ phpftp_passwd ){
Global $ phpftp_host;
$ Ftp = ftp_connect ($ phpftp_host );
If ($ ftp ){
If (ftp_login ($ ftp, $ phpftp_user, urldecode ($ phpftp_passwd ))){
Return $ ftp;
}
}
}

Function phpftp_list ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir ){
Global $ phpftp_host;
Phpftp_top ();
?>

$ Ftp = @ phpftp_connect ($ phpftp_user, $ phpftp_passwd );
If (! $ Ftp ){
?>
FTP login failed!
Start over?
Phpftp_bottom ();
} Else {
If (! $ Phpftp_dir ){
$ Phpftp_dir = ftp_pwd ($ ftp );
}
If (! @ Ftp_chdir ($ ftp, $ phpftp_dir )){
?>
Can't enter that directory!


$ Phpftp_dir = ftp_pwd ($ ftp );
}
Echo"Current host:". $ Phpftp_host ."
\ N ";
Echo"Current directory:". $ Phpftp_dir ."
\ N ";
If ($ phpftp_dir = "/"){
$ Phpftp_dir = "";
}

If ($ contents = ftp_rawlist ($ ftp ,"")){
$ D_ I = 0;
$ F_ I = 0;
$ L_ I = 0;
$ I = 0;
While ($ contents [$ I]) {
$ Item [] = split ("[] +", $ contents [$ I], 9 );
$ Item_type = substr ($ item [$ I] [0], 0, 1 );
If ($ item_type = "d "){
/* It's a directory */
$ Nlist_dirs [$ d_ I] = $ item [$ I] [8];
$ D_ I ++;
} Elseif ($ item_type = "l "){
/* It's a symlink */
$ Nlist_links [$ l_ I] = $ item [$ I] [8];
$ L_ I ++;
} Elseif ($ item_type = "-"){
/* It's a file */
$ Nlist_files [$ f_ I] = $ item [$ I] [8];
$ Nlist_filesize [$ f_ I] = $ item [$ I] [4];
$ F_ I ++;
} Elseif ($ item_type = "+ "){
/* It's something on an anonftp server */
$ Eplf = split (",", implode ("", $ item [$ I]), 5 );
If ($ eplf [2] = "r "){
/* It's a file */
$ Nlist_files [$ f_ I] = trim ($ eplf [4]);
$ Nlist_filesize [$ f_ I] = substr ($ eplf [3], 1 );
$ F_ I ++;
} Elseif ($ eplf [2] = "/"){
/* It's a directory */
$ Nlist_dirs [$ d_ I] = trim ($ eplf [3]);
$ D_ I ++;
}
}/* Ignore all others */
$ I ++;
}
?>













Directory empty or not readable


}
?>

If (count ($ nlist_dirs)> 0 ){?> }If (count ($ nlist_files)> 0 ){?> }} Else {?>

Directories



Files















Ftp_quit ($ ftp );
Phpftp_bottom ();
}
}

Function phpftp_cd ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir, $ select_directory ){
?>

$ New_directory = $ phpftp_dir. "/". $ select_directory;
Phpftp_list ($ phpftp_user, $ phpftp_passwd, $ new_directory );
}

Function phpftp_mkdir ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir, $ new_dir ){
?>

$ Ftp = @ phpftp_connect ($ phpftp_user, $ phpftp_passwd );
If ($ phpftp_dir = ""){
$ Phpftp_dir = "/";
}
If (! $ Ftp ){
@ Ftp_quit ($ ftp );
Phpftp_top ();
?>
FTP login failed!


Start over?
Phpftp_bottom ();
} Else {
$ Dir_path = $ phpftp_dir. "/". $ new_dir;
@ Ftp_mkdir ($ ftp, $ dir_path );
@ Ftp_quit ($ ftp );
Phpftp_list ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir );
}
};


Function phpftp_get ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir, $ select_file ){
$ Ftp = @ phpftp_connect ($ phpftp_user, $ phpftp_passwd );
If ($ phpftp_dir = ""){
$ Phpftp_dir = "/";
}
If ((! $ Ftp) | (! @ Ftp_chdir ($ ftp, $ phpftp_dir ))){
@ Ftp_quit ($ ftp );
Phpftp_top ();
?>
FTP login failed!


Start over?
Phpftp_bottom ();
} Else {
Srand (double) microtime () * 1000000 );
$ Randval = rand ();
$ Tmpfile = $ phpftp_tmpdir. "/". $ select_file. ".". $ randval;
If (! Ftp_get ($ ftp, $ tmpfile, $ select_file, FTP_BINARY )){
Ftp_quit ($ ftp );
Phpftp_top ();
?>
FTP get failed!


Start over?
Phpftp_bottom ();
} Else {
Ftp_quit ($ ftp );
Global $ use_mime_lookup;
If ($ use_mime_lookup = "1 "){
$ File_mime_type = mime_lookup (substr (strrchr ($ select_file, "."), 1 ));
}
If (! $ File_mime_type ){
$ File_mime_type = "application/octet-stream ";
}
Header ("Content-Type:". $ file_mime_type );
Header ("Content-Disposition: attachment; filename =". $ select_file );
Readfile ($ tmpfile );
}
@ Unlink ($ tmpfile );
}
}

Function phpftp_put ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir, $ userfile, $ userfile_name ){
Srand (double) microtime () * 1000000 );
$ Randval = rand ();
$ Tmpfile = $ phpftp_tmpdir. "/". $ userfile_name. ".". $ randval;
If (! @ Move_uploaded_file ($ userfile, $ tmpfile )){
Phpftp_top ();
?>
Upload failed! Can't create temp file?


Start over?
Phpftp_bottom ();
} Else {
If (! $ Ftp = @ phpftp_connect ($ phpftp_user, $ phpftp_passwd )){
Unlink ($ tmpfile );
Phpftp_top ();
?>
FTP login failed!


Start over?
Phpftp_bottom ();
} Else {
Ftp_chdir ($ ftp, $ phpftp_dir );
Ftp_put ($ ftp, $ userfile_name, $ tmpfile, FTP_BINARY );
Ftp_quit ($ ftp );
Unlink ($ tmpfile );
Phpftp_list ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir );
}
}
}

Switch ($ function ){
Case "dir ";
Phpftp_list ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir );
Break;
Case "cd ";
Phpftp_cd ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir, $ select_directory );
Break;
Case "get ";
Phpftp_get ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir, $ select_file );
Break;
Case "put ";
Phpftp_put ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir, $ userfile, $ userfile_name );
Break;
Case "mkdir ";
Phpftp_mkdir ($ phpftp_user, $ phpftp_passwd, $ phpftp_dir, $ new_dir );
Break;
Case "";
Phpftp_login ();
Break;
}

?>

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.