Using PHP's fopen in windows on a network drive - windows

I have the following code:
$file_name = "1234";
$filename = "L:\\videoette_converter\\batch_files\\".$file_name.'.bat';
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
I get the following error from that code:
Warning: fopen(L:\videoette_converter\batch_files\1234.bat)
[function.fopen]: failed to open stream: No such file or directory in
C:\wamp\www\videoette_converter\index.php on line 47
and the debug line from my php
Cannot open file (L:\videoette_converter\batch_files\1234.bat)
However the folder L:\videoette_converter\batch_files does exist as a mapped drive, and I have given "Everyone" full permissions. What could be the problem?

Are you sure there's no domain controller in the way?
When the Windows machine that serves the files is in an Active Directory domain:
1) The machine that runs the WAMP must be in the same domain.
2) The account used to run the Apache service on your WAMP machine must have at least read rights on the share you want to access. Instead of running the Apache service as "Local System" or "wampapache" you should specify your domain user account. (P.S.: I like XAMPP over Wamp for this kind of development, but that's probably just a personal preference)
Also I'm guessing id'd be better if you used a UNC path instead of a drive letter. It always worked for me that way. You don't need to use escaped backslashes, you can replace them with single forward ones:
//yourwinserver/sharename/path/to/file.bat

Related

Directory path not recognized by JSCH on Windows with mksnt toolkit

I have a windows VM which has been configured with the mksnt toolkit. So what that would imply is my path would become C:/abc/xyz
I am trying to connect from a linux box using Jsch utilty to this windows machine remotely. I am able to connect successfully and when I try to check for a particular directory path, it says it does not exist. However, the path does exist on the windows box.
Following is my Jsch code that looks for the destination directory -
SftpATTRS dirAttributes=null;
try{
testLog.info("Looking for directory :"+destinationDir);
dirAttributes = sftpc.stat(destinationDir);
} catch(SftpException s){
testLog.info("Directory does not exists !!!\n"+s.fillInStackTrace().toString());;
} catch (Exception e){
testLog.info("Directory does not exists !!!\n"+e.fillInStackTrace().toString());;
}
The above code works seamlessly if I do Linux <-> Linux remote calls and validate the directory but with Linux <-> Windows I am encountering this issue.
Since mksnt is installed, if I go to the directory and do "pwd" - it prints "C:/abc/xyz"
I am not clear if Jsch is not able to handle or recognize the paths due to mksnt installed.
Could anybody please share any solution or provide some pointer that may help me to resolve this.
PS: I cannot install cygwin or any other tool. This is the env. provided to me and I need to make remote calls from Linux host via Jsch utility only.
C:/abc/xyz
The SFTP protocol uses a unix-like naming scheme for file pathnames, regardless of the SFTP server's operating system. In the SFTP naming scheme, absolute pathnames begin with "/". A name beginning with "C" would reference a file in the SFTP session's working directory.
In other words, a Windows-based SFTP server might not interpret this pathname the way you expect it to. You should use an interactive SFTP client to log into the Windows SFTP server, locate the files and/or directories that you're interested in, and determine the correct path to use to access them through SFTP.
If the Windows SFTP server is running the Cygwin OpenSSH SFTP server, I believe the correct path would be something like "/cygdrive/c/abc/xyz".
I have faced the same issue in the past and I have solved using the following code:
String remoteFolder = "C:\temp\test"
remoteFolder = "/" + remoteFolder.replace("\\", "/");
With this JSCH can detect if the remote path exists or not. This is only required in Windows.

how to set directory permissions of windows server 2012 so Visual Basic 2015 windows app ‘kill’ doesn’t get file permission error

I have a Visual Basic windows app that reads incoming SMTP email files from c:\inetpub\mailroot\Drop\ and then moves them renamed to c:\primary\ .
I’ve set Windows file permissions of both directories c:\inetpub\mailroot\Drop\ and c:\primary\ to “everyone” full access.
I have a 2nd VB.NET windows app that reads each file, processes it, then deletes it using ‘kill(filepath)’ which gets the error:
“An unhandled exception of type 'System.UnauthorizedAccessException' occurred in Microsoft.VisualBasic.dll
Additional information: Access to the path '\\C\Primary\9255551212#vzwpix.com #71615 1.TXT' is denied.”
The file’s property > Security has “everyone” full access.
How do I set file permissions for the directories to prevent this error and be safe from hacker attack and not use “everyone” permission?
SOLUTION: Changed \\C to just "C:".

GhostScript on IIS6 causing Permission Denied error

I'm running a server with Windows 2003 and IIS 6.0. I'm using GhostScript to create pdf's that are a subset of pages from the full text using WScript.shell. The line (111) that is giving me the error message is:
iReturn = oShell.Run(gs\bin\gswin32c.exe -sDEVICE=pdfwrite -q -dNOPAUSE -dBATCH -sOutputFile="temppdf\pdfpp2_5.pdf" -dFirstPage=2 -dLastPage=5 "pdfComplete\LargeFile.pdf", 0, true)
--Most is done through scripting and variables, I've filled out file names just for continuity.
Here is the error message:
Microsoft VBScript runtime error '800a0046'
Permission denied
sendpdf.asp, line 111
I have given the IIS user full permissions on all folders involved. Does anyone see anything that I am missing or have a thought where I should go from here? Thanks!
To solve this issue...
Go to IIS Manager --> Local Computer
-->Application Pools.
Then, right click on DefaultAppPool then select Properties
Under the Identity Tab, check how your system is running them
An update evidently changed mine from "Configurable" so I can list what I want and set it to "Network Service". If you are VERY confident in your security (or are just using it for Intranet or the like), you could set it to "Local Service" or "Local System", but I would highly recommend against that except in extreme cases. A day full of research is complete!
Check the permissions of the Temp folder as well. The IIS should have permissions to the Temp folder

Apache 2 using Include with full path

I'm attempting to set up a test environment where the software is being developed on host machines then tested in a Virtual Machine and the VM has all code mapped to a Z:/ drive. My issue is that Apache is complaining and won't start up saying that I have an invalid Include path of Z:/source/myconf.conf. Anyone have luck previously of setting conf files up in a different different drive path that can help me understand what I'm doing wrong? I've tried with and without quotes as well.
Include path statement:
Include "Z:/source/myconf.conf"
Additional info:
Z is a virtual drive through VMWare also known as \\vmware-host
The specific error in the Application logs is as follows:
The Apache service named reported the following error:
httpd.exe: Syntax error on .. of C:/.../httpd.conf: Invalid Include path Z:/source/myconf.conf
Seems like its finding issue connecting to the Z drive and as z is the network drive, it must require user name and password which is creating issue
solution
If we can save the user name and password so that it won't ask for user credential dbl clicking to z drive.
To save permanently the user credential
Open command prompt and type
"net use Z: \servername\sharename /persistent:yes /savecred"
Now restart and see it should not ask user credential to connect to z drive and the apache error won't be there.

ora-12154 could not resolve... with oracle instant client

Here are the details:
I installed the oracle instant client 11.2.0.2.0 from the OTN download page on a windows 7 64 bit vm (vmware).
I am trying to to connect to a remote oracle database, and I can successfully connect with one program using TNS, but not with SQL*Plus and other applications.
Trying to connect with SQL*Plus, using schema#servicename, password, etc, gives the above error.
To connect via SQL Developer, normally I would use the basic connection info and not rely on tnsnames, but trying a normal connection gives me: io error: unknown host specified. SQL Developer can successfully connect and query database if i use the TNS protocol.
Trying from other programs gives me the same error I got with SQL*Plus. Same when trying with the service name from tnsnames.
This is obviously quite frustrating for it to work one way and not the other. I followed all the normal instructions for using the instant client, the directory with instantclient has been addded to the PATH, a TNS_ADMIN entry has also been created, with the directory to the tnsnames.ora file
Well, on a whim, I went to changing everything in my setup to match an windows 2003 server that i had setup with instant client before. The main changes were putting the instant client in a folder at the root of the drive (not program files/oracle/etc), but c:/oracle, i know ive seen other posts saying that oracle was particular about characters in the directory path, maybe spaces are a no-no too?
I also add a bunch more environmental variables, anythign that was on the other machine, ORACLE_HOME (to root of instance), SQL_PATH (same), and added the root of the directory to the PATH system variable, not just the folder with the instantclient files. Anyways, I'm happy its working, anyone one of these changes could have been it though-
You may use ProcessMonitor and look at what your sqlplus process is doing. In my case TNS_ADMIN was correctly defined but, by mistake, my tnsnames.ora and sqlnet.ora had a stupid ".txt" extension, added by default by notepad when I created those files. And because "Windows Explorer" has the "Hide extensions for known file types" option set by default, the naming error wasn't obvious at all.
I installed the 12.1 instant client. For me, the problem was solved by creating \network\admin\tnsnames.ora file. Here's the PowerShell I used:
$source = "C:\Users\USER1\Desktop\tnsnames.ora"
$target = "C:\oracle\product\12.1.0\client_1\network\admin"
mkdir $target
copy-item $source $target

Resources