Solved

ftp md5 Hash directory files.

Posted on 2009-07-09
4
863 Views
Last Modified: 2012-05-07
Hello, i am reading the files of a remote server directory and i am able to get results as can be seen from var_dump(). However i am having some trouble to create a md5_file() from the array given. Thank you for your assistance in this matter!
<?

		// Open a session to an external ftp site

		$ftp_server = 'ftp.mywebsite.com';

		$ftp_user_name = 'user@mywebsite.com';

		$ftp_user_pass = 'mypass';

		$ftp_port = '21';

		$remote_dir1 = 'public_html/dir1';

		// set up basic connection

		$conn1 = ftp_connect($ftp_server)or die("Could not connect to {$ftp_server}\n");

		$login_result1 = ftp_login($conn1, $ftp_user_name, $ftp_user_pass)or die("Could not login with {$ftp_server}\n");

		$dir1 = ftp_nlist($conn1, $remote_dir1)or die("Could not login with {$remote_dir1}\n");

		// output $contents

		var_dump($dir1);

		

		

		if(ftp_pwd($conn1)) {

		 foreach($dir1 as $file1) {

            //loop through it

                $hash = md5_file($conn1.$remote_dir1."/".$file1);

				$d[$hash] = $file1;

				}

			}

	

		else { 

			echo "Failed - Is not readable";

			}

?>

Open in new window

0
Comment
Question by:zefex
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:profya
ID: 24817963
Try this:
$hash = md5_file($remote_dir1."/".$file1);

Open in new window

0
 
LVL 14

Expert Comment

by:profya
ID: 24818045
You may need to check if $file1 is a file or directory, you can use ftp_size function, if it returned -1 then it is a directory.

if (ftp_size($conn1, $file)!==-1)

     $hash = md5_file($remote_dir1."/".$file1);

Open in new window

0
 

Author Comment

by:zefex
ID: 24820447
@profya

Thank you for your response, i tried the code as you mention, but still there is no md5 results.

this is only results i am getting:

array(10) { [0]=>  string(1) "." [1]=>  string(2) ".." [2]=>  string(14) "1207910176.jpg" [3]=>  string(14) "1207942539.jpg" [4]=>  string(14) "1207943063.jpg" [5]=>  string(14) "1207944104.jpg" [6]=>  string(8) "logo.png" [7]=>  string(10) "screen.jpg" [8]=>  string(13) "sss-games.jpg" [9]=>  string(29) "title-summer-slots-series.jpg" }


                if(ftp_pwd($conn1)) {

                foreach($dir1 as $file1) {

				//loop through it

                if (ftp_size($conn1, $file)!==-1){

				//if its not a directory and the file exists

				$hash = md5_file($remote_dir1."/".$file1);

                $d[$hash] = $file1;

												 }

										}

								

}

Open in new window

0
 

Accepted Solution

by:
zefex earned 0 total points
ID: 24833117
MD5 was not working well with FTP so i  read the files then storeded the file names to a cache file for comparison. Worked like a charm!

  // Retrieve File List
  $files = ftp_nlist($conn, $remote_dir);

  $currentFiles = array();
  if(file_exists($cache_file))
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP/Magento not logging 2 35
setup wamp server for first time 2 43
Should I use subdomains or addon domains? 3 35
How to loop through records  using SELET COUNT 2 14
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now