この記事では、リモートサーバーとの間でファイルを転送する方法について説明します。
SCPまたはRsyncを使用したファイルとディレクトリのコピー
SecureShell(SSH)またはRemote Sync(Rsync)を使用して、ファイルをリモートサーバーに転送できます。SecureCopy(SCP)は、SSHを使用して、選択したファイルまたはディレクトリのみをコピーします。最初の使用では、Rsyncはすべてのファイルとディレクトリをコピーし、次に変更したファイルとディレクトリのみをコピーします。すべてのファイルとディレクトリが再度コピーされるわけではありません。
SSHとSCPの例
リモートサーバーからファイルをコピーします:
~$ scp [email protected]:/path/file_name /local/destination/path/
リモートサーバーからディレクトリをコピーします:
~$ scp -r [email protected]:/path/directory[/] /local/destination/path/
ファイルをリモートサーバーにコピーします:
~$ scp /local/path/file_name [email protected]:/destination/path/
ディレクトリをリモートサーバーにコピーします:
~$ scp -r /local/path/directory[/] [email protected]:/destination/path/
Rsyncの例
Rsyncはファイルを再帰的に転送するため、-r
を追加する必要はありません。 国旗。次のコマンドを使用して、archivedor圧縮方式でファイルを転送できます。
-
-a
または--archive
:再帰と同様に、このオプションは権限などのソース特性を保持します。 -
-v
または--verbose
:このオプションは、転送中の詳細情報を表示します。 -
-z
または--compress
:このオプションを使用すると、Rsyncは宛先マシンに送信されるファイルデータを圧縮します。
リモートサーバーからファイルをコピーします:
~$ rsync [-avz] [email protected]:/path/file_name /local/destination/path/
リモートサーバーからディレクトリをコピーします:
~$ rsync [-avz] [email protected]:/path/directory[/] /local/destination/path/
ファイルをリモートサーバーにコピーします:
~$ rsync [-avz] /local/path/file_name [email protected]:/destination/path/
ディレクトリをリモートサーバーにコピーします:
~$ rsync [-avz] /local/path/directory[/] [email protected]:/destination/path/
ソースパスの末尾のスラッシュ(/)は、転送動作を変更して、宛先に追加のディレクトリレベルが作成されないようにします。スラッシュを使用すると、Rsyncは新しいフォルダーを作成せずにディレクトリコンテンツをコピーします。スラッシュを付けないと、ソースディレクトリ名で新しいディレクトリが作成されます。以下は、スラッシュがある場合とない場合の例です。
~$ rsync [-avz] /local/path/directory/ [email protected]:/destination/path/
~$ rsync [-avz] /local/path/directory [email protected]:/destination/path/
コメントや質問をするには、[フィードバック]タブを使用します。私たちと会話を始めることもできます。