Securely Transfer Files Over The Network
Securely Transfer Files Over The Networksftp-scp.jpgSecure File Transfer Protocol (SFTP)SFTP, or Secure File Transfer Protocol, is a network protocol that provides file access, file transfer, and file management functionalities over any reliable data stream. It is typically used with the SSH protocol to provide secure file transfer, but it can be used with other protocols as well.Use SFTP:sftp username@remote-hostThis command will initiate an SFTP session with the remote-host. It will be prompted to enter the password for the username connecting with.Once in the SFTP session, we can use ls to list files, cd to change directories, get to download files, and put to upload files. Here are syntax for reference:Server ActionsCommand SyntaxChange directorycd /etc/test or cd PATHList filesls dirCreate directorymkdir directoryDelete directoryrmdir directoryShow current directorypwdChange groupchgrp groupname PATHChange ownerchown username PATHChange permissionschmod 644 PATH (where 644 is an example of permissions)Create linkln oldname newnameDelete file or directoryrm PATHRename file or directoryrename oldname newnameExit serverexit, bye, or quitClient ActionsCommand SyntaxChange local directorylcd PATHList local filesllsCreate local directorylmkdir directoryShow current local directorylpwdUpload file to serverput [local directory or file] [remote]Download file from serverget [remote host directory or file] [local machine]Wildcards supportedUse * or *.rpm in file names for uploading/downloading multiple filesSecure Copy Protocol (SCP)Secure Copy Protocol (SCP) is a means of securely transferring computer files between a local and a remote host or between two remote hosts. It uses SSH for data transfer and provides the same authentication and security as SSH.i. (push file) The example of using SCP to transfer files:scp "/path/to/localFile" username@remote-host:/path/to/remoteDirectoryThis command will copy the file localFile from local machine to the remoteDirectory on the remote-host. ii. (push directory) The example of using SCP to transfer directory, the -r (recursive) option is require:scp -r /path/to/localDirectory username@remote-host:/path/to/remoteDirectoryiii. (pull file) To copy a file from the remote host to local machine:scp username@remote-host:/path/to/remoteFile /path/to/localDirectoryOptionDescription-pPreserves the original file's permissions and metadata.-rRecursively copies directories and their contents.-l speedLimits the transfer speed to the specified rate in Kbps. For example, -l 800 limits the speed to 100 KB/s.Transfer files via TAR on SSHTAR over SSH provides end-to-end encryption, which means that the contents of the transferred files are protected from unauthorized access. It also allows you to transfer multiple files or directories in a single archive, which can be more efficient than transferring them individually.tar czf - /path/to/directory | ssh user@remotehost "tar xzf - -C /remote/path"This command will create a compressed tarball of the directory located at /path/to/directory, and then pipe the output to the ssh command, which will connect to the remote host as user and extract the contents of the tarball to the directory located at /remote/path.ActionsCommand SyntaxCreate compressed tarball of a directorytar czf - /path/to/directoryPipe output to SSH command``Connect to remote hostssh user@remotehostExtract tarball to specify directorytar xzf - -C /remote/pathc: Create new archivetar cz: Compress with gziptar zf: Write archive to filetar f-: Output to stdout instead of filetar -x: Extract files from archivetar xConclusionThese are the fundamentals of using sftp, scp, and tar on Linux. They are robust tools that, once mastered, can greatly aid in managing and transferring files between systems.Referencessh 用戶端連線程式 - Linux 用戶RelatedRSYNC USAGESynchronization Solution on Windows (RSYNC)