Copy file from Linux to Windows file and folder sharing

Posted on

In order to be able to copy file from Linux operating system to another host, server or workstation which is installed with a Windows operating system where the file exists as a file and folder sharing, below are the steps which is needed to be done :

1. By using samba-client package which is assumed already installed in the linux operating system distribution, the process of copying files can be executed. First of all please check whether the samba-client package has already been installed by reading this article on checking installed package in Ubuntu Linux or suit the way with the environment of the operating system in the server.

2. If the  samba-client package hasn’t been installed yet, read this article to know how to install the package.

3. After successfully installed samba-client package, try to type it in the bash prompt just to make sure that the command can actually be called. The utility is ‘smbclient’ which is a command part of the samba-client package. Below is how to use the command :

smbclient

The output of the command :

user@hostname:~$ smbclient
WARNING: The "syslog" option is deprecated
Usage: smbclient [-?EgBVNkPeC] [-?|--help] [--usage] [-R|--name-resolve=NAME-RESOLVE-ORDER] [-M|--message=HOST] [-I|--ip-address=IP] [-E|--stderr]
[-L|--list=HOST] [-m|--max-protocol=LEVEL] [-T|--tar=<c|x>IXFqgbNan] [-D|--directory=DIR] [-c|--command=STRING] [-b|--send-buffer=BYTES]
[-t|--timeout=SECONDS] [-p|--port=PORT] [-g|--grepable] [-B|--browse] [-d|--debuglevel=DEBUGLEVEL] [-s|--configfile=CONFIGFILE]
[-l|--log-basename=LOGFILEBASE] [-V|--version] [--option=name=value] [-O|--socket-options=SOCKETOPTIONS] [-n|--netbiosname=NETBIOSNAME]
[-W|--workgroup=WORKGROUP] [-i|--scope=SCOPE] [-U|--user=USERNAME] [-N|--no-pass] [-k|--kerberos] [-A|--authentication-file=FILE]
[-S|--signing=on|off|required] [-P|--machine-pass] [-e|--encrypt] [-C|--use-ccache] [--pw-nt-hash] service <password>
user@hostname:~$

The above command is the output and to be able to use it properly it is needed to be added with the correct attribute, parameter and other things so that the copy process can actually worked out.

4. To be able to copy file, it can be done by executing the command as follows :

smbclient //IP_Address_shared_server/shared_name -l IP_Address_shared_server -W workgroup_name -U username -c "put path_of_folder_and_file_which_is_going_to_be_copied path_of_folder_and_file_name_which_is_going_to_be_the_target"

To make it simple, below is the pattern which is intended :

smbclient //IP_Address_shared_server/shared_name -l IP_Address_shared_server -W workgroup_name -U username -c "put path_of_folder_and_file_which_is_going_to_be_copied path_of_folder_and_file_name_which_is_going_to_be_the_target"

For an example :

smbclient //192.168.99.99/share_folder -l 192.168.99.99 -U user -c "put /home/user file"

Description : 
smblient : The tool which is actually a command used to connect to specific file and folder sharing
//192.168.99.99/share_folder : The address of file and folder sharing
-l : It is an optional parameter
-U : It is an optional parameter specified to pass username
user : It is the value of username optional parameter
-c : It is an optional parameter specified to pass command string
"put /home/user file" : It is the string command which is used as the value of -c optional parameter

The above command when executed in the command line will copy a file named ‘file’ located in /home/user to the folder and fie sharing of a shared name ‘share_folder located in the host which has an IP Address of 192.168.99.99.

One thought on “Copy file from Linux to Windows file and folder sharing

Leave a Reply