GNU/Linux >> Linux の 問題 >  >> Linux

sftp を使用してファイルを安全に転送する方法 (例を含む)

sftp コマンドは、ftp の安全な代替手段であり、機能的には ftp と同じです。 OpenSSH デーモン sshd を実行しているサーバーにログオンするときは、ftp の代わりに sftp を使用します。 sftp と ftp の主な違いは、前者は暗号化を使用してネットワーク経由でパスワードを転送するのに対し、後者は使用しないことです。

sftp 構文

リモート システムに接続するための形式は次のとおりです。

# sftp [options] [user@]host

ヘルプを入力するか? sftp コマンドのリストを表示します。

sftp> help
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
reget remote [local]		Resume download file
help                               Display this help text
lcd path                           Change local directory to 'path'
lls [ls-options [path]]            Display local directory listing
lmkdir path                        Create local directory
ln [-s] oldpath newpath            Link remote file (-s for symlink)
lpwd                               Print local working directory
ls [-1afhlnrSt] [path]             Display remote directory listing
lumask umask                       Set local umask to 'umask'
mkdir path                         Create remote directory
progress                           Toggle display of progress meter
put [-Ppr] local [remote]          Upload file
pwd                                Display remote working directory
quit                               Quit sftp
rename oldpath newpath             Rename remote file
rm path                            Delete remote file
rmdir path                         Remove remote directory
symlink oldpath newpath            Symlink remote file
version                            Show SFTP version
!command                           Execute 'command' in local shell
!                                  Escape to local shell
?                                  Synonym for help
sftp> 

sftp を使用してリモート システムを接続する

次の例では、ローカル システムにユーザー testuser としてログオンし、リモート システム 192.168.219.149 に接続していると想定しています。

$ sftp [email protected]
Connecting to 192.168.219.149...
[email protected] password:
Connected to 192.168.219.149.
sftp>

正しいパスワードを入力すると、sftp> が表示されます 示されているようにプロンプ​​トします。ヘルプを入力するか?使用可能なコマンドのリストを表示します。

ディレクトリの移動とファイルの一覧表示

1. ローカル サーバーで現在のディレクトリを見つけるには:

sftp> lpwd
Local working directory: /root

2. リモート ホストで現在の作業ディレクトリを見つけるには:

sftp> pwd
Remote working directory: /root

3. 同様に、ローカル サーバーのディレクトリを変更するには、lcd コマンドを使用します:

sftp> lcd /tmp

4. リモート サーバーのディレクトリを変更するには、cd コマンドを使用します:

sftp> cd /tmp

5. リモート サーバーの現在のディレクトリにあるファイルを一覧表示するには:

sftp> ls
anaconda-ks.cfg         initial-setup-ks.cfg    test

6. ローカル サーバーの現在のディレクトリにあるファイルを一覧表示するには:

sftp> lls
file1  file2  file3

ディレクトリの作成と削除

1. リモート サーバーに新しいディレクトリを作成するには:

sftp> mkdir data

2. ローカル サーバーに新しいディレクトリを作成するには:

sftp> lmkdir testdir

sftp を使用してファイルとディレクトリをアップロードする

1. 次の例では、ファイルをアップロードするか、ファイルをローカル システムからリモート システムにコピーします。

sftp> put file1

2. 複数のファイルをリモート ホストに転送するには、mput を使用します (複数のプット) コマンド。

sftp> mput file1 file2 file3

3. ディレクトリをリモート ホストに転送できるようにするには、まずリモート ホストにディレクトリを作成し、転送を開始する必要があります。

sftp> mkdir /dir
sftp> put -r dir/

sftp を使用してファイルまたはディレクトリをダウンロードする

1. リモート ホストから 1 つのファイルをダウンロードするには、get コマンドを使用します。 コマンド。

sftp> get file1

2. 複数のファイルをダウンロードするには、以下のコマンドを使用します。

sftp> mget file1 file2 file3

3. ディレクトリを再帰的に (すべての内容とともに) ダウンロードするには:

get -r dir

sftp を終了または終了

出口に入る 、やめる 、またはさようなら 接続を閉じて sftp を終了します。

sftp> bye

または

sftp> quit

または

sftp> exit


Linux
  1. LinuxでsFTPを使用してファイル/ディレクトリをアップロードまたはダウンロードする方法

  2. SFTPプロトコルを使用してローカルマシンとリモートマシン間でファイルを転送する

  3. SCPを使用してファイルを安全に転送する方法

  1. Linuxでファイルを安全に転送するための14のSCPコマンド例

  2. Crocを使用してコンピュータ間でファイルとフォルダを安全に転送する

  3. 安全なファイル転送のためにSFTPコマンドを使用する方法

  1. SFTPプロトコルを使用してローカルマシンとリモートマシン間でファイルを転送する方法

  2. SCPとSFTPを使用してLinuxホスト間でファイルを安全にコピーする方法

  3. Pythonスクリプトを使用してSFTPサーバーからファイルをダウンロードする方法