Can i access a windows share directly from linux server and Copy files

6,421

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.

Share:
6,421

Related videos on Youtube

Kanishka Panamaldeniya
Author by

Kanishka Panamaldeniya

LinkedIn

Updated on September 18, 2022

Comments

  • Kanishka Panamaldeniya
    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
      didierc about 9 years
      Can you access the share from the shell? Which command did you use to mount the share on your Linux box?
    • Kanishka Panamaldeniya
      Kanishka Panamaldeniya about 9 years
      @didierc as i told in my question , mount was done by a previous system admin :(
    • didierc
      didierc about 9 years
      And my first question?
    • Kanishka Panamaldeniya
      Kanishka Panamaldeniya about 9 years
      i tried ping ip_address and it is working correctly
    • didierc
      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
      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
      didierc about 9 years
      So 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
      didierc about 9 years
    • Kanishka Panamaldeniya
      Kanishka Panamaldeniya about 9 years
      @didierc , Thanks a lot , i will try this one :)
  • Kanishka Panamaldeniya
    Kanishka Panamaldeniya about 9 years
    successfully 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
    didierc about 9 years
    No problem, please don't hesitate to ask other questions if needed.