Php web page ftp code 4 download files
<? Php
$ Ftpserver =$ _ POST [ftpserver];
$ Ftpport = $ _ POST [ftpport];
$ Ftpuser = $ _ POST [ftpuser];
$ Ftppassword =$ _ POST [ftppassword];
$ Ftp = @ ftp_connect ($ ftpserver, $ ftpport );
If (! $ Ftp) {echo "connecting to the FTP server". $ ftpserver. "Port". $ ftpport. "failed"; exit ;}
$ Rs = @ ftp_login ($ ftp, $ ftpuser, $ ftppassword );
If (! $ Rs) {echo "the user name or password is incorrect. An error occurred while connecting to the FTP server"; exit ;}
$ TargetDir = str_replace ("\", "/", stripslashes ($ _ POST [targetDir]);
$ Filename = substr (strrchr ($ _ POST [filelist], "/"), 1 );
Echo $ filename;
// Exit;
If (substr ($ targetDir, strlen ($ targetDir)-1) = "/")
{
$ Rs = @ ftp_get ($ ftp, $ targetDir. $ filename, $ _ POST [filelist], FTP_ASCII );
} Else {
$ Rs = @ ftp_get ($ ftp, $ targetDir. "/". $ filename, $ _ POST [filelist], FTP_ASCII );
}
If ($ rs)
{
If (substr ($ targetDir, strlen ($ targetDir)-1) = "/")
{
Echo "<script> alert ('file downloaded successfully, the path of the file on the local machine is [". $ targetDir. $ filename. "] '); window. close (); </script> ";
} Else {
Echo "<script> alert ('file downloaded successfully, the path of the file on the local machine is [". $ targetDir. "/". $ filename. "] '); window. close (); </script> ";
}
Exit; I am
} Else {
Echo "<script> alert ('file download failed. Check whether the target folder exists. The source file is [". $ _ POST [filelist]. "] '); window. close (); </script> ";
Exit;
}
?>