Using fopen with a samba share

I have a samba share set up and I'm trying to open a file from a Winblows box that's on my Linux box via fopen().  I know that I have to double up the slashes and that "real" file systems use forward slashes, but I still can't open the file.  What's the trick here?

My fopen() call:

fopen("////my_Linux_box_ip_address//my_path//my_file, "w");
JeepGuyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin_J_ParkerCommented:
Shouldn't that be
fopen("\\\\my_Linux_box_ip_address\\my_share_name\\my_path\\my_file, "w");
?

I don't know if you can use // for a Windows URL, although you can certainly use / characters for the rest of the path - you certainly wouldn't need double the number of forward slashes.  You only need \\\\ because \\ is a single quoted backslash in C or C++.
0
Kruger_monkeyCommented:
Shouldn't those slashes be \?  Emulated windows share.  You are using the direct linux path, try switching it to a windows based path.
0
JeepGuyAuthor Commented:
That's what I thought at first since I am indeed reading FROM a Windows box, but it doesn't work.  So, I figured maybe the windows box needs the other slashes....why that would be the case since it's the fopen function in the windows libraries is beyond me, but I've seen stranger things with the VS compiler ;-)
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Kruger_monkeyCommented:
What errors are you getting?  It's not so much that you are reading FROM a windows box, but are trying to access a "windows" type share, i.e. samba, which are accessed with \\'s.

It might be another error.  Do you have a phperror log?
0
Martin_J_ParkerCommented:
Can you actually connect to the share from your machine?  Have you checked that you have read and write permission (ie copied files to/from it)?
0
JeepGuyAuthor Commented:
Holy cow the responses on this forum are fast! :-)

I can connect to the share and the net view command shows the share, I can open & write files from windows exploder, permissions have been checked, ya-da-ya-da, so the connection is all good.  I can't get fopen to return w/o an error, however.  It said that it can't open the file.  I haven't checked the log on the Linux box yet, but now I have a new problem to tackle....I just found out that my hard disk is not feeling well and need to deal with that ASAP.
0
JeepGuyAuthor Commented:
Do I need any special service running on either the windows or Linux box?  i.e. tftpd, httpd, etc.
0
Martin_J_ParkerCommented:
No, you are just opening a standard UNC - but you must remember to put the share name in the path and the path name will be relative to the share, not the fully qualified Linux path:
fopen("\\\\my_Linux_box_ip_address\\my_share_name\\my_path\\my_file, "w");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kruger_monkeyCommented:
Just a thought actually, assuming you can access the file through windows, i.e. copy your path from within fopen, paste that into run and see if it opens.  If that works fine, how is the file being accessed?  Web page with fopen?  If so, does the account that your webserver is running under have access to the file/location?

Had problems in the past on a linux box, trying to do an fopen, but apache didn't have access to that folder.  As soon as I granted permission it worked.  That wasn't a samba share though....
0
Martin_J_ParkerCommented:
Have you tried fopen onto a windows share from your PC?
It would be good to know if it's a generic fopen problem or a Samba specific one.
0
JeepGuyAuthor Commented:
It works with windows shares just fine.  The problem is with Samba shares.  I can't test it at the moment though because of my hd issue that just came up.  I think I already tested it with the share name before, but I can't remember.  I should get the hd issue resolved today so I can get back to testing by tomorrow.
0
Martin_J_ParkerCommented:
That's strange - Samba shares and Windows shares should behave the same way as far as the C/C++ code is concerned.  Does the fopen call produce a useful return code?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
File Sharing Software

From novice to tech pro — start learning today.