开发者

How to access a remote file in a windows drive from Ubuntu using php

I had this command in windows:

exec('copy /V "'.$file.'" "'.$dest.'"');

where $file is a REMOTE file in a windows drive of the form:

\\server\dr1$\folder\file
\\server\dr2$\folder\file
\\server\dr0$\folder\file
\\server\dr1$\folder\file2
\\server\dr1$\folder\file1

and so on. And destination is a local file in the server. Notice that drives change all the time, and that there are not known in advance (they come from a db result). In Windows everything is fine, the executed command will be something like this (/V is to verify the file is copied correctly):

copy /V \\server\dr1$\folder\file c:\users\test\file

however, I don't know how to run that in Linux, when I try

cp \\server\dr1$\folder\file /home/test/file

I get:

cp: cannot stat '\\server\dr1$\folder\file': No such 开发者_JAVA百科file or directory.

Thanks,

Nano.


You need to use Samba/CIFS to mount the drive before you copy to/from it.

This would look something like:

mount -t cifs //servername/sharename ./mountpoint/
cp ./mntpoint/folder/file /home/test/file

Theres quite a bit of documentation on this. Try googling smbclient or cifs.


You can use PHP to exec smbclientcommands. Smbclient behaves much the same like FTP, there are a couple of classes out there to assist you on the PHP side of things.

Alternatively you can mount the filesystem in user space via FUSE (look at https://serverfault.com/search?q=fuse+cifs for that), copy the files and unmount the drive again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜