Jump to content

Recommended Posts

Hi,

 

I want to connect to a computer in my network, where the computer is password protected.

So what we normally do is, type \\<ip or computer name>. Then when it prompts for username and pass, we provide it in the pop-up window.

 

So, when we do a opendir('directory name'), it opens normally. but what to do if this ddirectory has some pass.

 

Please help. This is really urgent and I am stuck up.

 

My Code is

 

<?php

function open_dir ($dir_name)
{
if ($handle = opendir ($dir_name)) 
{
while (($file = readdir($handle)) != false)
	{
		if ($file != '.' && $file != '..')
		if (filetype($dir_name.'/'.$file)== 'dir')
		{
			open_dir ($dir_name.'/'.$file);
		}
		else
		{
			echo $file." ";
			echo "-------------";
			insert_into_database ($dir_name, $file);
		}
	}
closedir($handle);
}
}

open_dir ("\\\\192.168.1.2\folder");

?>

 

What to do if "\\\\192.168.1.2\" computer in the network has password

Link to comment
https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/
Share on other sites

You need to map the network drive instead of accessing it like a ..... network share

 

Here's a good post on it (note that it's in the PHP manual... under opendir)

http://us.php.net/manual/en/function.opendir.php#90373

Hi, Thanks a lot for your reply.

I have seen this tutorial on php.net. But could not build my code accordingly. So, I am supplying with the credentials. If possible, PLZ help me  write the code

 

IP to be connected : 192.168.1.4

Folder to be accessed : \\19.168.1.4\folder1\folder_test

Username of 192.168.1.3 : user

Password of 192.168.1.3 : pass

 

I just want to access folder_test directory.

 

Sir, plz help


// Define the parameters for the shell command
$location = "\\192.168.1.4\folder1\folder_test";
$user = "USERNAME";
$pass = "PASSWORD";
$letter = "Z";

// Map the drive
system("net use ".$letter.": \"".$location."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");

// Open the directory
$dir = $letter . ":";
function open_dir ($dir_name)
{



if ($handle = opendir ($dir_name)) 



{



while (($file = readdir($handle)) != false)





{







if ($file != '.' && $file != '..')







if (filetype($dir_name.'/'.$file)== 'dir')







{









open_dir ($dir_name.'/'.$file);







}







else







{









echo $file." ";









echo "-------------";









insert_into_database ($dir_name, $file);







}





}



closedir($handle);



}
}

?>

that's the best I can come up with

If I type net use Z: \\192.168.1.5\Databases\data\account PASSWORD /user:USERNAME /persistent:no in command prompt and then I try to access Z: thorugh COmmand prompt, it works.

 

But If I try to do the same using PHP, it says "Warning: opendir(Z:) [function.opendir]: failed to open dir: No error in C:\wamp\www\knet\handle.php on line 28"

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.