Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Transfer file

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Abstract: this paper introduces several kinds of network shared file transfer under linux: NFS, Samba, FTP and sftp based on SSH transmission protocol. This article only describes how to use existing shared resources, not the configuration of the server for the time being.

1. Network hard disk between linux: NFS.

NFS is currently only used to share file systems between linux and UNIX hosts. NFS makes it easy to mount the file system on a linux (or UNIX) host locally. Of course, this requires the other host to turn on the NFS server and set up the shared file system.

(1) how to install the NFS file system?

Just like installing a local file system, the difference is that you need to specify a remote hostname (or IP address) for the mount command.

Example: sudo mount 192.168.1.111:/default / mnt # installs the / default exported on host 192.168.1.111 to the mnt directory

After a successful installation, you can use it like a local file. If the installation fails, it may be because the server-side NFS server did not export this directory correctly. You can use showmount with the-e option to view the server-side exported directory.

Example: showmount-e 192.168.1.111 # View the directory exported by host 192.168.1.111

(2) when installing the file system, we can choose the appropriate installation option to mount the file system:

By default, the mount command selects the appropriate installation options based on the settings on the NFS server. If you determine that the NFS server exported the filesystem writable, you can use the-o option with the rw flag to explicitly mount the filesystem as read / write.

Example: sudo mount-o rw 192.168.1.111:/default / mnt # mounts in read / write mode

Note: the rw flag actually "recommends" the mount command to mount the file system in a read-write manner. If the setting on the NFS server does not allow external writeability, mount automatically chooses to install as read-only.

The commonly used NFS installation flags are:

Rw: mounts the file system in a read-write manner.

Ro: mounts the file system as read-only.

Bg: if the installation fails, continue to send the installation request in the background.

Hard: "hard installation" mode. If the server does not respond, temporarily suspend access to the server until the server resumes.

Soft: "soft installation". If the server does not respond, an error message is returned and the operation being performed is interrupted.

Intr: allows the user to interrupt an operation and return an error message.

Nointr: users are not allowed to interrupt.

Timeo=n: the timeout of the request. N is measured in 1/10 seconds.

Tcp: transfer files using TCP protocol (UDP is selected by default)

Async: requires the server to respond to the client's write request before actually writing to the disk.

"hard installation" is the default installation of the mount command, which helps stabilize the NFS transport. If the transmission of a program is temporarily blocked for network reasons, the client will continue to wait until the transmission returns to normal. In contrast, in a "soft installation", a brief failure can destroy hours of labor. But if the user is dealing with a less important NFS server, the soft flag helps avoid wasting time on unnecessary waiting.

Intr allows users to interrupt an operation when it does not respond. In general, "hard installation" with the intr flag is a better way than "soft installation", which not only ensures that important operations will not be accidentally interrupted, but also allows the user to interrupt an operation at the appropriate time.

Separate several different options with commas. The following command mounts the remote NFS file system as a read / write, hard mount, interruptible, and background retry mount request.

Example: sudo mount-o rw,hard,intr,bg 192.168.1.111:/default / mnt

(3) unmount a file system: just like unmounting a local file system, use the umount command.

Example: sudo umount / mnt

(4) if you need to let the machine mount the remote NFS file system automatically during Qidong, you can configure it by modifying / etc/fstab.

For example: 192.168.1.111:/default / mnt nfs rw,hard,intr,bg 00 # file system type is nfs

2. Share transmission with Windows: Samba.

(1) NFS is not used in Windows, but the protocol mechanism of CIFS is used to share files. CIFS is essentially an upgraded version of SMB, which was developed by Andrew Tridgell in 1991 using reverse engineering to implement the SMB protocol. Tridgell named the developed package Samba.

(2) Samba includes a server and several client programs. Samba server-side programs installed on linux hosts provide linux sharing to Windows machines, and Windows hosts do not need to install other special tools for this. The client program of Samba is used to obtain the shared content of Windows hosts.

(3) smbtree: used to view shared resources on the current network.

-S option: simply list the shared hosts on the current network. When smbtree asks for a password, enter directly (indicating that no password is required). If the-S option is not specified, smbtree attempts to establish a connection with the searched shared host.

-U: you can specify which user name to connect to and provide the corresponding password.

-b: specifies that smbtree searches the entire network using broadcasts.

Example: smbtree-b-U smbuser # broadcasts the entire network and specifies the user smbuser to establish a connection with the searched shared host.

(4) nmblookup: you can query the IP address of a CVM. This command is good if you need to use an IP address to access Samba resources.

Example: nmblookup lewis-laptop # queries the IP address of lewis-laptop

(5) smbclient: get Samba shared resources. Basic syntax: smbclient / / servername/sharename [- U username]

Example: smbclient / / 172.16.25.128/share

After a successful login, smbclient will display "smb:\ >" to prompt the user for a command. The commands here are similar to those of FTP and sftp. Introduced in FTP.

Quit: quit.

(6) mount.cifs: Mount the shared directory of windows to the local directory.

Syntax: mount.cifs service mount-point [- o options] # service represents a shared directory on the server side, which, like smbclient, should be written as / / servername/sharename. Mount-point represents the local directory used to mount the share.

Example: sudo mount.cifs / / 10.171.20.225/share / srv/share

3. Use FTP:

(1) use web browser: use web browser to connect to FTP, remember to add "ftp://" prefix" in the address to tell the browser to use the FTP protocol.

(2) FTP graphics client: FIleZilla is commonly used. Do not introduce the details, it is very simple.

(3) use ftp command:

Ftp: a command-line FTP tool that comes with linux that performs all basic FTP operations. To connect to the server using the ftp command, simply follow the command with the server name or IP.

Example: ftp 10.171.37.1 # connects to FTP server 10.171.37.1

The FTP server uses port 21 by default, and if FTP does not use the default port, you can add another port parameter to the host.

Example: ftp 10.171.37.1 2121 # connects the FTP daemon working on port 2121.

After the connection is established, the ftp command asks for a login user name. If you are connecting to an anonymous FTP server (that is, a FTP server that anyone can access), you should type anonymous to represent the anonymous user. After the login is successful, you can see the ftp prompt and wait for the user to enter the command: ftp >.

The commands used by the ftp program to browse the file system are basically the same as shell.

Common ftp client commands:

!: execute commands locally.

?: displays help for the ftp command.

Open: connect to the FTP server.

Close or disconnect: close the connection without exiting the FTP program.

Bye or quit: exit the FTP program.

Cd: switch the directory where the remote is located.

Ls or dir: lists the contents of the remote directory.

Get: download the file.

Mget: download multiple files at a time.

Put: upload files.

Mput: upload more than one file at a time.

Mkdir: create a directory on the FTP server.

Rmdir: delete the directory on the FTP server.

Delete: delete files on the FTP server.

Pwd: displays the directory where the current remote is located.

Lcd: switch the local directory.

Prompt: switch between interactive and non-interactive modes.

4. File transfer based on SSH: sftp and scp.

The main results are as follows: (1) due to the unencrypted transmission mode, the traditional FTP has serious security risks, and SSH is one of the most secure and reliable transmission protocols at present. Using sftp for file transfer helps secure user accounts and transfers. First make sure that the host has the SSH daemon turned on, and then use the following command to establish a connection.

Example: sftp lewis@10.171.32.73 # establishes a connection with the user lewis.

After the connection is successful, it appears: sftp >. Wait for the user to enter a command, which is similar to FTP.

(2) scp: used to assign some files from the server.

Example: scp lewis@10.171.33.221:/home/lewis/dump-0.4b41.tar.gz / srv/nfs_share/

# copy the file dump-0.4b41.tar.gz from / home/lewis on server 10.171.33.221 to / srv/nfs_share/ as lewis.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report