Jump to content

Recommended Posts

I am wanting to create a system, if not already done by someone else that someone can direct me to, to check if the files on my local computer are the same as that on the server. maybe using MD5.

I use XAMPP and wish to code this in PHP.

The only issue I have is the first step, accessing the sites files using FTP via PHP and XAMPP.  The rest of the PHP code I should be able to do ok.

Any suggestions how I might be able to access FTP using PHP in XAMPP ?

Thank you

My main goal is to have my PHP code show a list of files on the server and whats local and list them and show which files have changed on the server and if any files are missing and if any new files are there that are not present in my local folder.

Edited by jason310771
Link to comment
https://forums.phpfreaks.com/topic/317125-access-ftp-using-php-in-xampp/
Share on other sites

And you need to do this over ftp? The only want to compare the contents of a file over FTP is to download the file and read it locally. If you have to do that, and if you're optimistic that the remote server's files are almost the same as your local files, then you might as well download all the files and do a normal local-local comparison.

To do this in PHP, I would first recommend writing something that can compare files in two local directories. Because the complication here is going to be in the comparison work - not in the FTP work.

For the FTP work, though, PHP already has built-in support for doing many file operations using the ftp:// stream wrapper and it might work for you.
https://www.php.net/manual/en/wrappers.ftp.php
If you have something that can compare two directories, then switching one of those two be "ftp://..." could work.

If you're not aware of it already, I'll also throw out RecursiveDirectoryIterator as a hint. That lets you read files from a directory and also open files for reading.

The "might" is because I don't know how the ftp:// wrapper handles connections: if it is able to reuse one (besides the PASVs) then that's great, but if it tries to create a new session every time you call something like file_get_contents then you should probably go with the regular ftp extension instead.
So that's something for you to investigate: can you use RecursiveDirectoryIterator without it creating unnecessary connections?

Well, to access FTP using PHP in XAMPP you can utilize PHP built in FTP function. 

Code Example: 

<?php
// Server credentials
$ftpServer = 'your_ftp_server_address';
$ftpUsername = 'your_ftp_username';
$ftpPassword = 'your_ftp_password';

// Connect to the FTP server
$connId = ftp_connect($ftpServer);

if (!$connId) {
    die('Could not connect to the FTP server');
}

// Log in to the FTP server
$loginResult = ftp_login($connId, $ftpUsername, $ftpPassword);

if (!$loginResult) {
    die('FTP login failed');
}

// Get a list of files in the remote directory
$files = ftp_nlist($connId, '/path/to/remote/directory');

// Output the list of files
print_r($files);

// Close the FTP connection
ftp_close($connId);
?>
<?php
// Server credentials
$ftpServer = 'your_ftp_server_address';
$ftpUsername = 'your_ftp_username';
$ftpPassword = 'your_ftp_password';

// Connect to the FTP server
$connId = ftp_connect($ftpServer);

if (!$connId) {
    die('Could not connect to the FTP server');
}

// Log in to the FTP server
$loginResult = ftp_login($connId, $ftpUsername, $ftpPassword);

if (!$loginResult) {
    die('FTP login failed');
}

// Get a list of files in the remote directory
$files = ftp_nlist($connId, '/path/to/remote/directory');

// Output the list of files
print_r($files);

// Close the FTP connection
ftp_close($connId);
?>

Thanks

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.