Can i access a windows share directly from linux server and Copy files
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:
$ smbclient -L <hostname>
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 to smbclient
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 from smbclient
, which is a bad practice. If possible, you should try to make manual backups, where your credentials would be provided interactively.
Related videos on Youtube
Comments
-
Kanishka Panamaldeniya over 1 year
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 .
-
didierc about 9 yearsCan you access the share from the shell? Which command did you use to mount the share on your Linux box?
-
Kanishka Panamaldeniya about 9 years@didierc as i told in my question , mount was done by a previous system admin :(
-
didierc about 9 yearsAnd my first question?
-
Kanishka Panamaldeniya about 9 yearsi tried ping ip_address and it is working correctly
-
didierc about 9 yearsÀ simple "solution" is to use the smbclient program to access the share using a smbfs style path to the share and username/password as parameter. This doesn't use the mount point installed by your predecessor. From php, you may use the
system
function to execute a shell command. -
Kanishka Panamaldeniya about 9 years@didierc , can you provide an answer for this , i am very new to this thing , and i am really stuck here :)
-
didierc about 9 yearsSo if you've got that smb path to the share (you can check it out from the network neighbourhood on a Windows box, or on a Linux box well configured to scan a windows network - normally an default install ubuntu desktop should do fine).
-
didierc about 9 years
-
Kanishka Panamaldeniya about 9 years@didierc , Thanks a lot , i will try this one :)
-
-
Kanishka Panamaldeniya about 9 yearssuccessfully connected to the windows share , had to use username and password also , now trying to copy files from Ubuntu to windows ;) . Thank you very much .
-
didierc about 9 yearsNo problem, please don't hesitate to ask other questions if needed.