I have a windows share created using samba .
It is located in my ubunutu server /mnt/user_new
I want to copy files from /var/www/myproject/files/
to /mnt/user_new/files
. This is for backup my files . and delete the original files .
I am using PHP . form PHP i tried
$file = '/var/www/html/bmw/myproject/files/0000000.pdf';
$newfile = '/mnt/user_new/0000000.pdf';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}
But i get a permission denied error .
Severity: Warning
Message: copy(/mnt/user_new/0000000.pdf) [function.copy]: failed to open stream: Permission denied
Is there any way to copy files from my Linux server to windows share . I have a username and password for access window share , but i don't know how to use it here . is there any way i can pass username and password .
To be honest this is my first time working with Samba , and the windows share is created by Network administrator . I have spent nearly 8 hours for this simple copy . but could not do .
Please help me . thanks in advance .
So, your Linux server has a windows share mounted on a local directory, but apparently you cannot write to it. I suppose that this share has been setup as guest access, hence the read only status. Please refer to the ubuntu documentation on mounting windows share as a starting point to fix this configuration issue.
As a work around for the time being, I suggest using the
smbclient
from the command line or a shell script to perform your backups. This command can help you find out the path of the windows share if necessary:but as I suggested in the comments, it might be simpler to just look it up from a FS browser (Gnome, KDE, or even a windows shell). This program acts more or less like a ftp client on top of the SMB/CIFS protocols, but it requires precise parameters, so you will have to investigate. For instance, if your windows server belongs to an active directory domain, you will have to pass the
-k
parameter tosmbclient
to let it know. You will also have to pass username and password along on the command line. There are many other parameters discussed on the man page, which could be important depending on your situation (eg. Do you need to encrypt the connection?).In interactive mode, as mentioned earlier, this program works like a ftp client, so if you are familiar with ftp commands, you should feel at home with this tool. It is also possible to pass a sequence of ftp instructions on the command line, which is probably what you'll want to use to automate the backups until the share mount is fixed.
Finally, I also mentioned the
system
php function which comes handy when needing to invoke a shell command from a php script. Again, all this should be used a temporary solution until the share is fixed: you will have to write your credentials somewhere in the scripts or in a file configuration file accessible fromsmbclient
, which is a bad practice. If possible, you should try to make manual backups, where your credentials would be provided interactively.