This sample code shows you how to connect to a remote FTP server using PHP's built-in functions, retrieve a text file and save it on the current server.
1. $FtpCon = ftp_connect("www.geekpedia.com");
2. $FtpLog = ftp_login($FtpCon, "charley", "4815162342");
3.
4. if ((!$FtpCon) || (!$FtpLog))
5. {
6. echo "FTP connection failed.";
7. exit;
8. }
9. else
10. {
11. echo "FTP connection successful.";
12. }
13.
14. $LocFile = fopen("SaveTo.txt","w");
15. $RemFile = ftp_fget($FtpCon, $LocFile, "SaveFrom.txt", FTP_BINARY);
16.
17. if (!$RemFile)
18. {
19. echo "Could not obtain file.";
20. }
21. else
22. {
23. echo "File retrieved successfully!";
24. }
25.
26. ftp_close($FtpCon);