How to copy a file from unix to windows machine, from commandline

How to copy a file from unix machine to windows machine, from commandline.

-

migrated from stackoverflow.comSep 27 '11 at 21:33

This question came from our site for professional and enthusiast programmers.

Assuming that, the Windows box have a shared folder. You can use smbclient command. Which provide a FTP-like command line interface over the SMB protocol.

This post provide a ready to use example, which looks a perfect answer.

If you need to copy files to or from a windows server from a unix server, you can use an utility from the Samba software suite called smbclient.

Here is an example to copy a file to a Windows server:

 smbclient //WIN_SERVER/SHARE -l WIN_SERVER_IP -A AUTHFILE -c "put
TRANSFER_FILE_LOCAL TRANSFER_FILE_REMOTE"


where:

WIN_SERVER = the name of your Windows server

SHARE = the name of your Windows share

AUTHFILE = full path to your authentication file name. The file contents should include:

username = mywinuser
domain = MYDOMAIN


TRANSFER_FILE_LOCAL = full path to Unix file to transfer

TRANSFER_FILE_REMOTE = new file name on Windows server

For more help or options using smbclient, type "smbclient -h"

-
Top tip. I used smbclient //winhost01/myshare -W mydomain -U myuser -c "get path\to\_readme.txt _readme.txt" –  wmorrison365 May 12 at 13:31

If your windows machine is on the same network, you can share your unix filesystem with smb and mount it on the windows machine, then use "cp" to transfer the file.

You can find information about smb for ubuntu here https://help.ubuntu.com/10.04/serverguide/C/samba-fileserver.html

-
What if the script is running on the Unix side? –  awashburn Jan 7 at 20:48