Using smbclient to operate Windows Shared Files

Source: Internet
Author: User

When a Windows Server is installed, You need to upload some files to the operating system. However, when this segment is only Linux, we can think of two methods:

    1. Use Remote Desktop to mount a local hard disk
    2. Transmission through the SSH service

However, in some cases, the Windows operating system is not customized through PXE, and Remote Desktop Connection is a multinational, so it is affected by the lack of SSH service or slow network speed of the other party. When you need to transmit a large file, you can only mount the local hard disk on the Remote Desktop. After a long wait, the system notifies you that the path cannot be found! Crash, and you have to hand over your fate to the network again ....

Is there a better way? The answer is yes, and there are not only many. Here we will introduce a method that is often ignored:

Escape the file to the local network, and then use smbclient to upload the file to the target Windows server.

Usage conditions:

    1. Enable the server service on Windows server to provide external sharing services
    2. Smbclient is installed on the source file server, which is usually installed by default.
    3. Access Windows shared directory permissions: user name and password

Usage

  1. View the shared directory of the target Windows Server
    # Smbclient-l // 10.12.0.1/-uadministrator

    Password:
    Domain = [MyServer-55D13420A0] OS = [Windows Server 2003 R2 3790 Service Pack 2] Server = [Windows Server 2003 R2 5.2]

    Sharename type comment
    --------------------
    IPC $ IPC? IPC
    C $ disk Category Q?
    ADMIN $ disk ??
    Session Request to 10.12.0.1 failed (called name not present)
    Session Request to 10 failed (called name not present)
    Domain = [MyServer-55D13420A0] OS = [Windows Server 2003 R2 3790 Service Pack 2] Server = [Windows Server 2003 R2 5.2]

    Server comment
    ----------------

    Workgroup master
    ----------------

  2. Connect to the shared directory of the target Windows Server (the hidden share of the drive will be enabled after Windows is installed, and administrator permission is required. The access path is drive letter + $)
    # Smbclient // 10.12.0.1/C $-uadministrator
    Password: (enter the correct password)
    Domain = [MyServer-55D13420A0] OS = [Windows Server 2003 R2 3790 Service Pack 2] Server = [Windows Server 2003 R2 5.2]
    SMB: \> (if a prompt is displayed, the connection is successful)
  3. Upload files
    SMB: \> put file1.rar (upload a single file)
    SMB: \> mput file1.rar file2.rar (upload multiple files)
  4. Download files
    SMB: \> Get file1.rar (download a single file)
    SMB: \> mget file1.rar file2.rar (download multiple files)
  5. Change the remote shared directory
    SMB: \> Cd DOC (relative to the shared directory)
  6. Use account permissions to connect and automatically execute commands
    # Smbclient // 10.12.0.1/C $-u administrator % password-c "put file1; quit"
  7. More commands

    ? Chmod get listconnect mget posix_mkdir PWD rename stat vuid
    Altname chown getfacl lock mkdir posix_open Q reput symlink wDEL
    Archive close hardlink logon more posix_rmdir queue RM tar
    Blocksize del help lowercase mput posix_unlink quit rmdir tarmode
    Cancel dir history ls newer print RD setmode translate
    Case_sensitive du LCD mask open prompt recurse showacls unlock
    CD exit link md posix put reget showconnect volume

  8. Exit
    SMB: \> quit

Note:

    1. An existing shared directory must exist after the connection path.
    2. The shared directory must have file access permissions.
    3. The parameters of the smbclient command must be placed after the machine name; otherwise, the command will be treated as the server address.
    4. After the file transfer is completed, you must immediately disable the server service for Windows to ensure system security.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.