7

I am writing a script (Bash) to transfer files from my local Linux machine to Windows servers. The Windows servers are accessible normally using the SAMBA shares, and I am able to mount a folder to my Linux machine using the mount.cifs command with the proper Windows credentials.

Because I do not want to mount every server in advance nor mounting dynamically using sudo (the script is executed as a normal user, not root), I am just wondering if the server can be accessed by another means, like a TCP pipe or a similar way.

For example, under Windows I can mount my server's folder to a drive letter using the net use command, but as well without having being mounted like this:

c:> net use \\my-server.domain.com passwd123 /user:domain\myuser
c:> cp d:\myfiles.zip \\my-server.domain.com\d$\temp\destination

And if I make a net use, I can see the open connection (without letter assigned):

    Status       Local     Remote                    Network
-------------------------------------------------------------------------------
OK                     \\myserver.domain.net\IPC$
                                                Microsoft Windows Network
The command completed successfully.

I do not want to install sshd nor ftpd on the Windows Server. I am looking to do it only with the SMB protocol. As a fallback I will execute a mount like sudo mount.cifs [options] /mnt/temp-folder and sudo umount /tmp/temp-folder after the copy of the files.

Peter Mortensen
  • 1,029
  • 1
  • 8
  • 10
рüффп
  • 1,677
  • 4
  • 27
  • 35
  • What you can do on the Windows server depends intrinsically on what services are running on it. If you were running an sshd, e.g., you could scp a file. If you had nc, you could have it listen on a port and redirect it straight into the output filename. &c. &c. – Tom Hunt Sep 04 '15 at 15:14
  • What about using putty on the windows side? Putty will allow a windows machine to ssh and call a command, as well as scp. That would enable you to trigger the script and copy the results using the windows server. There might also be a tools that goes the opposite direction, a linux tools that lets you transfer to windows instead of a windows tool that lets you transfer to/from linux. – Centimane Sep 04 '15 at 15:41

2 Answers2

17

You can use the smbclient program to give you an FTP-like interface to the Windows file share without having to install FTP on the Windows machine.

Here follows some examples:

Transfer file from local (unix/linux) to Windows:

smbclient //server.domain.org/d$ <password> -W domain.org -U <my-user> -c "put file-local.xml folder1\folder2\file.xml"

Transfer file from Windows to Linux:

There are two options, the first is using the command 'get' with smbclient and a the second, a shortest one: smbget:

1. smbclient: `smbclient //server.domain.org/d$ <password> -W domain.org -U <my-user> -c "get folder1\folder2\file.xml file-local.xml"`
2. smbget: `smbget -u <my-user> -p <password> -w domain.org -o destination-file.txt smb://server.domain.org/d$/folder1/folder2/source-file.txt`
рüффп
  • 1,677
  • 4
  • 27
  • 35
John
  • 16,759
  • 1
  • 34
  • 43
2

You might try something like wput [options] [file]... [url]... ftp://[username[:password]@]hostname[:port][/[path/][file]] or wget

quintablet
  • 86
  • 4