Connect to the FTP server with PHP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | /******************************************************* * MYCPLUS Sample Code - https://www.mycplus.com * * * * This code is made available as a service to our * * visitors and is provided strictly for the * * purpose of illustration. * * * * Please direct all inquiries to saqib at mycplus.com * *******************************************************/ <html> <head> <title>ftp_connect</title> </head> <body> <? //connect to server if(!($ftp = ftp_connect("localhost"))) { print("Unable to connect!<br />\n"); exit(); } print("Connected.<br />\n"); //log in { print("Unable to login!<br />\n"); exit(); } print("Logged In.<br />\n"); //print system type print("System Type: " . ftp_systype($ftp) . "<br />\n"); //make sure passive mode is off ftp_pasv($ftp, FALSE); //get working directory print("Working Directory: " . ftp_pwd($ftp) . "<br />\n"); //get files in raw format print("Raw List:<br />\n"); foreach(ftp_rawlist($ftp, ".") as $line) { print("$line<br />\n"); } print("<br />\n"); //move to pub directory if(!ftp_chdir($ftp, "pub")) { print("Unable to go to the pub directory!<br />\n"); } print("Moved to pub directory.<br />\n"); //get a list of files print("Files:<br />\n"); foreach(ftp_nlist($ftp, ".") as $filename) { print("$filename<br />\n"); } print("<br />\n"); //return to root directory if(!ftp_cdup($ftp)) { print("Failed to move up a directory!<br />\n"); } //close connection ftp_quit($ftp); ?> </body> </html> |