5

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

3 Answers 3

8

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

WIN_SERVER_IP = the IP address of your Windows server

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

username = mywinuser
password = mywinpass
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"

2
  • Top tip. I used smbclient //winhost01/myshare -W mydomain -U myuser -c "get path\to\_readme.txt _readme.txt" May 12, 2014 at 13:31
  • 1
    to place the file at a certain location on Windows. Use "cd dir1/dir2; put localFile" as argument to "-c" where the desired destination is //WIN_SERVER/SHARE/dir1/dir2 and the local file to transfer is localFile.
    – Champ
    Jun 30, 2015 at 15:37
1

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

1
  • What if the script is running on the Unix side?
    – user169983
    Jan 7, 2014 at 20:48
0

You can use PSFTP to download/upload files to / from Unix server from your Windows machine.

You may see this guide.

1
  • The link is dead
    – gnibbler
    Aug 28, 2019 at 5:46

You must log in to answer this question.