ローカルからリモートにコピー
a.txtをローカルからリモートの/remote/directoryにコピーする場合
$ scp a.txt username@remote.example.com:/remote/directory
リモートからローカルにコピー
リモートの/remote/directory/a.txtをローカルの/local/directoryにコピーする場合
$ scp username@remote.example.com:/remote/directory/a.txt /local/directory
ローカルのディレクトリごとリモートにコピー
オプション-rを使う。
$ scp -r local_dir username@remote.example.com:/remote/directory
鍵認証を使ってリモートにコピー
オプション-iで鍵のパスを指定する
$ scp -i ~/.ssh/id_rsa a.txt username@remote.example.com:/remote/directory
ポート番号を指定してリモートにコピー
オプション-Pでポートを指定する
$ scp -P 2222 a.txt username@remote.example.com:/remote/directory
複数ファイルをリモートにコピー
ローカルのa.txtとb.jpgをリモートにコピーする場合
$ scp a.txt b.jpg username@remote.example.com:/remote/directory
ローカルのa.txt、b.txt、c.txtをリモートにコピーする場合
$ scp {a,b,c}.txt username@remote.example.com:/remote/directory
ローカルの現在のディレクトリにあるすべての.txtファイルをリモートにコピーする場合
$ scp *.txt username@remote.example.com:/remote/directory
複数ファイルをローカルにコピー
リモートのa.txtとb.jpgをローカルにコピーする場合
$ scp username@remote.example.com:/remote/directory/\{a.txt,b.jpg\} .
リモートのa.txt、b.txt、c.txtをローカルにコピーする場合
$ scp username@remote.example.com:/remote/directory/\{a,b,c\}.txt .
リモートのディレクトリにあるすべての.txtファイルをローカルにコピーする場合
$ scp username@remote.example.com:/remote/directory/*.txt .