Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ How to use secure FTP file transfer     - Encrypted with GnuPG signature to verify the authenticity and integrity of downloaded file (Linux)

- CentOS 5.5 kernel upgrade installation iftop (Linux)

- List Leaves (Programming)

- Python substring format (Programming)

- Github Remote Assistance (Linux)

- Fast Sort Algorithms (Programming)

- Installation Flow N Play- interface stylized video player on Ubuntu (Linux)

- Why is better than Git SVN (Linux)

- Install Xshell on Mac OS X (Linux)

- MongoDB upgrade from 2.4.9 to 2.6.0 and PHP record of mongo extension upgrade from 1.4.5 to 1.5.1 (Database)

- Android Studio installed in Ubuntu 15.04 (Linux)

- How to identify memory leaks in Java (Programming)

- Build the first ASP.NET 5 Web project in Mac OS X Yosemite 10.10.3 (Server)

- C # C ++ Java interface type conversion (Programming)

- Java regular expression syntax (Programming)

- Find details block device with Linux blkid command (Linux)

- Linux System Getting Started Tutorial: How to Force Change your password at next logon Linux (Linux)

- Linux server alarms using Java (Server)

- Oracle 11g logical standby achieve BI needs (Database)

- Multipath configuration under Linux (Linux)

 
         
  How to use secure FTP file transfer
     
  Add Date : 2018-11-21      
         
         
         
  What is SFTP?

Before understanding SFTP, let's look at what is FTP. FTP (File Transfer Protocol) file transfer protocol, is coming between two end systems a common method of transferring files.

SFTP, namely SSH File Transfer Protocol (SSH File Transfer Protocol), or a secure file transfer protocol (Secure File Transfer Protocol). SFTP is a separate SSH packet encapsulation protocol, connected in a similar manner by security. Its advantage is that it can use a secure connection to transfer files, but also through the file system on the local and remote systems.

In most cases, preference SFTP instead of FTP, SFTP most basic reason is that the security features and the ability to use SSH connection. FTP is an insecure protocol, you should only trust networks or use under certain circumstances.

Although SFTP integrates many graphics tools, but this is a use guide will demonstrate how to use an interactive command line interface to use it. The following is a guide.

How to use SFTP connections

By default, SFTP using SSH protocol for authentication and establish a secure connection. For this reason, in the same present in the SSH authentication method is available.

Although by default the way, is very convenient to use and set up a password, we strongly recommend that you build a SSH key to your public key pass you need access to all systems. In the long run, it will be more secure, but also save your time.

If you have not set up SSH key, click here to see the SSH key guide to set up your SSH key to access your server.

If you can use SSH to connect to your host, then you have completed all the necessary requirements for use SFTP to manage your files up. Use the following command to test SSH access:

ssh username @ remote_hostname_or_IP

If the previous command is successful, enter the command exit:

exit

Establish an SSH connection open an SFTP session. This process can use the following command:

sftp username @ remote_hostname_or_IP

This way, you connect to a remote system, you will become SFTP prompt prompt.

In SFTP command line help documentation

The old rules, to understand the most useful commands - help, it will help give you an overview of SFTP. You can enter any of the following to open the help of the two:

help

?

After that, you can use the following command will display a list:

Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
                                   filesystem containing 'path'
exit Quit sftp
get [-Ppr] remote [local] Download file
help Display this help text
lcd path Change local directory to 'path'
...
Next, we'll explore some of the above commands.

SFTP Shell Basic Operations

We can use most similar to the machine Shell commands to navigate through the directory structure.

First, we have to determine the current working directory, how to determine it? Shell sessions with most similar can enter the following command to get the current directory information:
pwd

Remote working directory: / home / demouser

Another familiar command - Content ls, view the current directory

ls

Summary.txt info.txt temp.txt testDirectory

It is noteworthy that, SFTP command line does not like such ships Shell Bash feature-rich, but the selectivity achieved some important parameters:

ls -la

drwxr-xr-x 5 demouser demouser 4096 Aug 13 15:11.
drwxr-xr-x 3 root root 4096 Aug 13 15:02 ..
-rw ------- 1 demouser demouser 5 Aug 13 15:04 .bash_history
-rw-r - r-- 1 demouser demouser 220 Aug 13 15:02 .bash_logout
-rw-r - r-- 1 demouser demouser 3486 Aug 13 15:02 .bashrc
drwx ------ 2 demouser demouser 4096 Aug 13 15:04 .cache
-rw-r - r-- 1 demouser demouser 675 Aug 13 15:02 .profile
...
Use the following command to switch to another directory:

cd testDirectory

Now we can traverse the remote file system! But if we need to access the local file system, how to do it? We just need to give these commands just add a prefix "l" (L lowercase), the operation can be realized on the local host.

So far, all we talked about the command has a corresponding local version, we can print the local host working directory:

lpwd

Local working directory: / Users / demouser

Similarly, we can list the contents of the machine so that the current working directory:

lls

Desktop local.txt test.html
Documents analysis.rtf zebra.html
Obviously, we also can easily switch back and forth in a Shell in the current working directory on the local host and the remote host:

lcd Desktop

Transfer files using SFTP

Only access the content between the two file systems can not transfer files between local and remote file systems, it is simply a cow tripod cooking chicken.

Download the remote file to the local host

If we want to download a file from a remote host, follow me do so:

get remote_file_name

Fetching / home / demouser / remoteFile to remote_file_name
/ Home / demouser / remote_file_name 100% 37KB 36.8KB / s 00:01
As you can see, by default, "get" command to download the file on the remote host to the local host and ensure that the same file name.

I want to change the name? no problem! Directly specify a different file name to copy the file to the remote:

get remote_file_name local_file_name

Here, I have to tell you, "get" command and some optional parameters. For example, we can open recursive option to recursively copy a folder inside the content:

get -r some_directory_name

We can also open the "-P" or "-p" parameter to tell SFTP maintaining access to the settings and bit file access time:

get -Pr some_directory_name

Upload a file to the remote host

Use see-known name meaning "put" command can easily upload files to a remote host:

put local_file_name

Uploading localFile to / home / demouser / local_file_name
local_file_name 100% 7607 7.4KB / s 00:00
"Put" similar "get" parameter. In this way, you can upload an entire folder:

put -r local_directory_name

note

In the current release of Ubuntu system (or at least 14.04-15.10) running on a version of OpenSSH has a BUG, ​​execute the above command error. When use of the BUG OpenSSH, in the implementation of the above command to transfer files to the server, will be reported this error: Could not canonicalise: No such file or directory

To solve this problem, you can enter mkdir local_directory_name on the remote system to the new destination directory. After this, execute the above command should not being given.

When we use to download and upload files to a well-known and useful tool - "df" command, and other command-line work in the same way. Through it, you can check whether there is enough space to complete the file you want to transfer:

df -h

 Size Used Avail (root)% Capacity
 19.9GB 1016MB 17.9GB 18.9GB 4%
Please note! This command has no corresponding ldf, but we can use the "!" The command to achieve the same purpose. (Here, I think LinuxStory article "at the Linux command line!" "Ten magic usage," is very good, it is recommended to not see a small partner, click here to get.)

This "!" (Exclamation-byte) command takes us back to the local Shell, where you can run all the commands available in our local system. By entering the following command to check our disk usage:

!
df -h

Filesystem Size Used Avail Capacity Mounted on
/ Dev / disk0s2 595Gi 52Gi 544Gi 9% /
devfs 181Ki 181Ki 0Bi 100% / dev
map -hosts 0Bi 0Bi 0Bi 100% / net
map auto_home 0Bi 0Bi 0Bi 100% / home
As such, any other local commands are as effective as you would expect. Back SFTP session, enter:

exit

Now, you should be able to see SFTP prompt back.

In fact, you can not quit SFTP Shell command to execute the local host, if you execute the Shell command VIM inside too, I think you should know what that means.

Simple to use SFTP file operations

SFTP allows you to perform basic file maintenance type, there is useful when the file system.

For example, you can use the following command to change the owner of the file on the remote system:

chown userID file

Please note that the system and "chmod" command, this command does not accept SFTP user name and replace it with the user's UID. Unfortunately, there is no easy way to give the corresponding UID via SFTP interface.

This thorny problem solve can use this command:

get / etc / passwd
! Less passwd

root: x: 0: 0: root: / root: / bin / bash
daemon: x: 1: 1: daemon: / usr / sbin: / bin / sh
bin: x: 2: 2: bin: / bin: / bin / sh
sys: x: 3: 3: sys: / dev: / bin / sh
sync: x: 4: 65534: sync: / bin: / bin / sync
games: x: 5: 60: games: / usr / games: / bin / sh
man: x: 6: 12: man: / var / cache / man: / bin / sh
...
Note that the "!" Instead of "l", and before this "l" prefix is ​​not the same, we can use it as in the same manner inside VIM local Shell command. Before it has been used on the local "df" command.

UID file will appear in the third column, defined by a colon.

Similarly, we can change the file belongs to the group:

chgrp groupID file

Again, I want to get the remote system GID is not so simple. We can use the same way to solve:

get / etc / group
! Less group
root: x: 0:
daemon: x: 1:
bin: x: 2:
sys: x: 3:
adm: x: 4:
tty: x: 5:
disk: x: 6:
lp: x: 7:
...
Clearly we can see the third column is the first column GID corresponding to the user's group. This is what we are looking for!
Fortunately, the "chmod" command can execute such commands on a remote file system:
chmod 777 publicFile

Changing mode on / home / demouser / publicFile
Although there is no ready-made commands to operate the local file permissions, but you can set the local umask. Thus, any files copied to the local system has the appropriate permissions.

Use "lumask" command to complete this operation:
lumask 022
Local umask: 022

Now all regular files download (as long as no open "-p" parameter) will have 644 permissions.

SFTP allows you to create a new directory on the local file systems and remote file systems, respectively, using "lmkdir" and "mkdir" command, this is definitely helpful!

This is the only remaining file commands for the remote file system:

ln
rm
rmdir
These commands copy version of the basic characteristics of Shell. If you need to perform these operations on the local file system, remember that you can enter this command to switch to Shell:
!
Or perform in a local system plus this command prefix, such as "!":

! Chmod 644 somefile

When you have completed the SFTP session, use the "exit" or "bye" to close the connection:
bye

to sum up

Although SFTP is a very simple tool, but use it to manage the server and between the client and server to transfer files it is very convenient.

If you are accustomed to using FTP or SCP to achieve your transmission, then you can try SFTP, which combines two of the director. Although it is not all as you like in all cases, but it is a flexible tool worth adding to your skills library!
     
         
         
         
  More:      
 
- Three easy open source firewall on the Linux platform (Linux)
- MySQL script incremental backups (innobackupex) (Database)
- How to modify the Linux NIC eth1 to eth0 (Linux)
- Swift used in the application to add a local push at the specified time (Programming)
- CentOS installation pycurl (Linux)
- Use Oracle Data Guard to complete cross-platform database migration cases (Database)
- About Leetcode on Binary Tree Algorithm summary (Programming)
- Management and application Oracle external table (Database)
- Ubuntu 14.04 + xRDP + Xfce implement Windows Remote Desktop Connection (Linux)
- C language keywords Comments (Programming)
- Qt for file splitting and fusion gadgets (Programming)
- JavaScript event handling Detailed (Programming)
- How to add a new resolution VirtualBox (Linux)
- 20+ Best Practices article MySQL Performance Optimization (Database)
- Offline (local) Yum source structures (Linux)
- Cobbler automatic mass deployment of CentOS 6 and CentOS 7 (Linux)
- Nginx logging client ip (Server)
- Linux add a new hard disk (Linux)
- Top command: the Task Manager under linux (Linux)
- Nagios (centreon) monitoring LVS (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.