3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

scpやsftpを使わずにsshだけでファイルをアップロードする

Posted at

単一ファイルのみの場合

ローカル側のファイルlocal.txtをcatで読み込み、それをsshにパイプして、サーバー側でファイルupload.txtにリダイレクトすることでアップロードができます。

※Windowsの場合、git-bash(gitをインストールするとついてくる)が必要です

cat local.txt | ssh -i *****.pem user@server "cat > ~/upload.txt"

複数ファイルをアップロードする場合

複数ファイルをアップロードしたい場合は、catの代わりにtarを使いアーカイブしてから転送します

  1. ローカル側でtarを使ってファイルをまとめる
  2. サーバーへアップロード(パイプで転送)する
  3. サーバー側で解凍する
# ローカルの転送ディレクトリ、リモートの出力先ディレクトリを指定する
LOCAL_DIR=*****   # ./test_upload
UPLOAD_DIR=*****  # ./
tar -zcf - $LOCAL_DIR | ssh -i *****.pem user@server "tar zxf - -C $UPLOAD_DIR"
  • tar の-は「標準入力/出力」を入出力先として利用するためのオプション
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?