SCPコマンドを介してサーバーとの間でファイルをコピーする
SCPは、セキュアシェル(SSH)を使用して、クライアントとリモートサーバー間でデータを転送します。これは、高速で安全です。 この記事では、2つの一般的なSCPコピーの例を示します。
-
コンピューターからリモートサーバーにデータをコピーします。
-
リモートサーバーからコンピューターへのデータのコピー。
1. リモートサーバーへのデータのコピー
例1.1–ファイルのコピー。
scp SourceFile user@server:directory/TargetFile
ユーザー名「example」を使用して、ファイル「gae.log」をローカルコンピューターからリモートサーバー(example.com)の「/home/example/
」フォルダーにコピーします。
$ scp gae.log [email protected]:/home/example/ Password: stdin: is not a tty gae.log 100% 4193 4.1KB/s 00:00
例1.2–フォルダーとそのすべてのコンテンツをコピーします。
scp -r SourceFolder user@server:directory/TargetFolder
ユーザー名「example」を使用して、フォルダ「tutorials」をローカルコンピュータからサーバー(example.com)の「/home/example/
」フォルダにコピーします。
$ scp -r tutorials [email protected]:/home/example/ Password: stdin: is not a tty aweber.txt 100% 2895 2.8KB/s 00:01 codetraining.txt 100% 330 0.3KB/s 00:00 contact.txt 100% 146 0.1KB/s 00:00 eclipse.txt 100% 5719 5.6KB/s 00:00
2. リモートサーバーからのデータのコピー
例2.1–ファイルのコピー。
scp user@server:directory/SourceFile TargetFile
ユーザー名「root」を使用して、ファイル「/home/example/modsec_audit.log
」をリモートサーバー(example.com)からローカルの現在のフォルダー(「.
」)にコピーします。
$ scp [email protected]:/home/example/modsec_audit.log . Password: stdin: is not a tty modsec_audit.log 100% 244KB 122.1KB/s 00:02
例2.2–フォルダーとそのすべてのコンテンツをコピーする。
scp -r user@server:directory/SourceFolder TargetFolder
ユーザー名「example」を使用して、フォルダー「/home/example/mail
」をリモートサーバー(example.com)からローカルの現在のフォルダー(「.
」)にコピーします。
Yongs-MacBook-Air:~ example$ scp -r [email protected]:/home/example/mail . Password: stdin: is not a tty courierimapuiddb 100% 15 0.0KB/s 00:00 courierpop3dsizelist 100% 88 0.1KB/s 00:01 courierimapacl 100% 43 0.0KB/s 00:00 maildirsize 100% 348 0.3KB/s 00:00
SSH Port
サーバーがデフォルト以外のSSHポート22を使用している場合は、-P portnumber
オプション(Uppercase P)を使用します。
scp -P 2222 user@host:directory/SourceFile TargetFile