Access remote file storage

I am a novice in programming world. Want to access remote file storage (windows server) from my cakephp application (linux server) using credentials.
I want to travers the directory and count the number of files in that directory.
I know how to access folder on same server. But have no idea about remote server access.
I tried something like this

    $path = '\\< IP >;
    $user = "< username >";
    $pass = "< password >";
    $drive_letter = "D";     //this is the drive name that I want to access
    system("net use ".$drive_letter.": \"".$path."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
    $location = $drive_letter.":/";
    $result = is_dir($location);
    echo $result;

But getting a blank page.
I don’t know whether I am on a right track.

Hey mate, welcome to the forums.

I won’t provide an answer to your question as your approach is fundamentally wrong. There are a number of significant security implications in how you’re trying to achieve this. I must assume your windows server is not using SSL (as if it was you wouldn’t be stuck where you are now) thus your traffic will be unencrypted - and you’ll be sending login credentials in plain text through who knows how many servers!

How much control do you have on that Windows Server? Is it hosting a PHP implementation? In which case develop for yourself a private API you can talk to, using your own CSRF protection in doing that. Then that API can respond to requests such as a directory listing.

Or else, you could do a push from the Windows Server to your application, using a [long] polled AJAX, so that the data you need which is on that server is duplicated locally in your CakePHP app - and changes on the server are reflected by posting those back to your CakePHP app.

Or, you could try using net sockets.

You must employ SSL regardless your approach.

I know these are only generic responses, not like working code of how-to, it’s just I feel you need to rethink how you should achieve your goal here.

Thankyou for the valuable information. I’ll try to dig into…

It also occurs to me, I mean if you’re not comfortable in learning and programming to that extent, you can get away with a mostly safe & hacky solution, which is to put a FTP server on the Windows box. Then you can do what you need with just bash scripts or PHP. Again though, must have end-to-end encryption, SSL (so it’ll be SFTP).

Oh thankyou… I am also trying the same