Upload Zip File to Server From Disk Centos

In my last article I shared the steps to encrypt a file using gpg key in Linux. At present in this article I volition share diverse commands and tools which you can use to securely re-create file from i server to another in Linux. There are additionally other ways to transfer files which I cannot cover hither for example you can also use HTTPS to upload and download files.

I may write some other article with detail list of steps to use HTTPS and curl for secure file upload and download.If you wish to copy files between Windows and Linux then you lot can always use Samba merely since here nosotros are targeting file transfer betwixt 2 Linux machines, I volition not share whatever steps related to Samba configuration.

5 commands to copy file from one server to another in Linux or Unix

Some more than articles on related topic you may be interested in

  • ii commands to copy folder from local to remote server or vice versa in Linux with examples
  • Step-by-Step Guide to setup SFTP chroot Jail to restrict user to a specfic directory when copying files in Linux
  • How to deeply transfer files between ii hosts using HTTPS in Linux

Using SFTP to copy file from one server to another

In computing, the SSH File Transfer Protocol (also Secure File Transfer Protocol, or SFTP) is a network protocol that provides file access, file transfer, and file direction over any reliable data stream.

SFTP is piece of cake to work with: You enter sftp along with the proper noun of the remote system on the command line. Yous are prompted for the business relationship password; and then you are dropped into SFTP with the connection open and waiting.

You tin can besides automate the file transfer using SFTP in beat script, or you tin also utilize one liner SFTP commands to perform file transfer rather than interactive sessions.

[deepak@Ban17-inst01-a ~]$ sftp -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no deepak@10.43.138.2 Password:

One time you give the password of deepak user on target node, you will become sftp shell

sftp> ls -fifty -rw-r----- 1 root root 401 Dec 7 11:53 new_key.pub -rw-r----- 1 deepak users 9 Dec x 14:13 pwd.txt drwxr-xr-ten two root root 4096 Nov 28 11:38 scripts -rw-r--r-- 1 root root 0 Dec x 14:07 test_file

Side by side to copy file from host to client (i.e. upload a file from host to client)
Here I have a file 'pwd.txt' on my host server under '/domicile/deepak/pwd.txt' which I wish to re-create to my client's current working directory

sftp>          put /home/deepak/pwd.txt .          Uploading /home/deepak/pwd.txt to /abode/deepak/./pwd.txt /dwelling/deepak/pwd.txt 100% 9 26.6KB/s 00:00

To re-create a directory and all it'due south content use (-r). Here /home/deepak/mydir is available on my host car which I am copying to the connected customer node under electric current working directory.

sftp>          put -r /dwelling house/deepak/mydir .          Entering /home/deepak/mydir/

So the file was successfully uploaded. You can verify the aforementioned

sftp>          ls          new_key.pub pwd.txt scripts test_file

Next copy a file from client node to your host server. I have a file 'test_file' on my client node nether '/home/deepak/test_file'

sftp>          get test_file /tmp/          Fetching /dwelling/deepak/test_file to /tmp/test_file

Validate the aforementioned on your host server

# ls -l /tmp/test_file -rw-r----- ane deepak deepak 0 Dec 10 14:09 /tmp/test_file

Yous can get more supported options from the homo page of sftp.

Using RSYNC to copy file from one server to another

rsync is a utility that you can use to copy file from one server to another very easily, and at that place are many options available to allow yous to exist very specific near how you want the data transferred. Another attribute that makes rsync flexible is the many ways y'all tin can manipulate the source and target directories. However, yous don't fifty-fifty take to use the network; you tin even copy data from one directory to some other on the same server.

Copying a file within the aforementioned server from one location to another

# rsync -r /home/deepak/mydir/test /tmp/

Here we are using -r to re-create recursively, you tin can also use (-a) i.e. for archive which retains equally much metadata every bit possible (in well-nigh cases, it should brand everything an exact re-create).

NOTE:
This works because whenever rsync runs, information technology will copy what's different from the concluding time it ran. The files from our first backup were already there, but the permissions were wrong. When we ran the second command, rsync only needed to re-create what was different, so information technology applied the correct permissions to the files. If any new files were added to the source directory since nosotros last ran the command, the new or updated files would be copied over every bit well.

To re-create files betwixt two servers

# rsync -av test deepak@ten.43.138.two:/tmp/ Countersign: sending incremental file list  sent 44 bytes received 12 bytes 22.40 bytes/sec total size is 5 speedup is 0.09

Using SCP to re-create file from one server to another

A useful alternative to rsync is the Secure Re-create (SCP) utility to re-create file from one server to some other, which comes bundled with OpenSSH. It allows y'all to speedily copy files from ane node to another. If your goal is to send a single file or a small number of files to another machine, SCP is a great tool you lot can use to get the task done. To utilize SCP, we'll use the scp control. Since you most likely already take OpenSSH installed, you should already have the scp command available

Using SCP is very similar in nature to rsync. The command requires a source, a target, and a filename. To transfer a single file from your local car to another, the resulting control would look similar to the following:

# scp -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/goose egg host_list deepak@10.43.138.2:/tmp/ Password: host_list 100% 30 83.2KB/s 00:00

If you do not specifiy the target directory while doing scp, then the home directory of the target user will be used are destination.

# scp -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/nix host_list deepak@10.43.138.two: Password:

IMPORTANT Notation:
Make certain you e'er include at least the colon when copying a file, since if you don't include it, you'll end up copying the file to your current working directory instead of the target.

With our previous scp examples, we've only been copying a single file. If we want to transfer or download an entire directory and its contents, we will need to apply the -r option, which allows us to do a recursive copy:

# scp -r -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null /domicile/deepak/mydir deepak@x.43.138.2: Password:

Using NFS to share file from one server to another

A Network File System (NFS) is a great method of sharing files between Linux or UNIX servers. I have written some other commodity with detailed steps to setup NFSv4 and NFSv3 with examples in RHEL/CentOS seven and 8 Linux

On my RHEL node I have installed nfs-utils and now volition setup my exports. To ready NFS, let'due south first create some directories that nosotros volition share to other users. Each share in NFS is known every bit an Export.

# cat /etc/exports /share *(rw,no_root_squash) /share 10.0.2.0/255.255.255.0(rw,no_root_squash)
  • In the outset line I have given share access to world for /share directory.
  • In the second line, after the directory is called out in a line, we're also setting which network is able to access them (10.0.2.0/255.255.255.0 in our case). This means that if you're connecting from a different network, your admission will be denied.
  • As far as what these options exercise, the first (rw) is rather self-explanatory.
  • One option you'll see quite frequently in the wild is no_root_squash. Normally, the root user on one system will get map to nobody on the other for security reasons. In nigh cases, one system having root access to another is a bad idea. The no_root_squash option disables this, and information technology allows the root user on one end to be treated as the root user on the other. .

Notation:
Check the homo pages for export for more data on additional options y'all can laissez passer to your exports.

Next restart your nfs-server services on the server

# systemctl restart nfs-server.service

To check the list of shares currently exported

# exportfs -v /share 10.0.two.0/255.255.255.0(rw,sync,wdelay,hide,no_subtree_check,sec=sys,secure,no_root_squash,no_all_squash) /share <world>(rw,sync,wdelay,hibernate,no_subtree_check,sec=sys,secure,no_root_squash,no_all_squash)

Now try to mount the directory /share from the client side

[root@node1 ~]# mount -t nfs node2:/share /mnt

So our directory mountain is successful, Next validate the content

[root@node1 ~]# cd /mnt/  [root@node1 mnt]# ls test1 test2

We tin can validate the aforementioned on our client node using beneath control

[root@node1 mnt]# mount | grep share node2:/share on /mnt type nfs4 (rw,relatime,vers=four.1,rsize=131072,wsize=131072,namlen=255,difficult,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.0.ii.20,local_lock=none,addr=10.0.two.21)

NOTE:
For our examples we take disabled the firewall and selinux. So if you confront whatsoever issues, check your iptables and selinux rules and add iptables rules to allow ssh connectedness.

After successfully mounting the share on the customer node, you tin can re-create the file locally to your node.

# cp -av /mnt/* /tmp/ '/mnt/test1' -> '/tmp/test1' '/mnt/test2' -> '/tmp/test2'

Using SSHFS to re-create file from one server to another

SSH Filesystem (SSHFS) is a file sharing solution like to NFS and Samba. NFS and Samba are great solutions for designating file shares but these technologies may be more complex than necessary if you want to prepare a temporary file-sharing service to use for a specific period of fourth dimension. SSHFS allows you to mount a remote directory on your local machine, and take information technology treated just similar any other directory. The mounted SSHFS directory will be available for the life of the SSH connection and tin can be used to re-create file from one server to another.

Drawbacks of using SSHFS

  • Functioning of file transfers won't exist as fast as with an NFS mountain, since at that place'due south encryption that needs to exist taken into consideration also
  • Another downside is that you lot'd want to save your work regularly equally you work on files within an SSHFS mountain, because if the SSH connection drops for any reason, you lot may lose data.

SSHFS is part of EPEL repository, which you can install using yum

# yum -y install sshfs

For SSHFS to piece of work, we'll need a directory on both your local Linux machine as well equally a remote Linux server. SSHFS can mount any directory from the remote server where y'all take SSH access.

Here I am mounting /share from node2 on node1

[root@node1 ~]# sshfs root@node2:/share /mnt root@node2's countersign:

Now validate the content of /mnt and make sure the path is properly mounted

[root@node1 ~]# cd /mnt/  [root@node1 mnt]# ls test1 test2  [root@node1 mnt]# mount | grep share root@node2:/share on /mnt blazon fuse.sshfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0)

Now you lot can copy the files from /mnt locally to any other directory

[root@node1 mnt]# cp -av * /tmp/ 'test1' -> '/tmp/test1' 'test2' -> '/tmp/test2'

In one case your copying is consummate, manually unmount the corresponding directory. There are 2 ways to do so. First, we can apply the umount control as the root (but like nosotros normally would):

[root@node1 ~]# umount /mnt/

Yous tin can also utilize HTTPS for file sharing, although information technology would be more like of file uploading and downloading via GET and PUT using curl command.

Lastly I promise the commands from this article to copy file from i server to some other in Linux or Unix was helpful. And then, let me know your suggestions and feedback using the comment department.

ortizvirstal.blogspot.com

Source: https://www.golinuxcloud.com/commands-copy-file-from-one-server-to-another-linux-unix/

0 Response to "Upload Zip File to Server From Disk Centos"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel