前提
Windows で圧縮した php ファイルを、サーバー上で解凍することに取り組んでいます。
TeraTerm を使用したことがあるので unzip コマンドを実行してみました。
実現したいこと
TeraTerm で php ファイルを unzip したいです。
なぜ下記 該当のソースコード・実行の流れ の流れでそれができないのか、そして TeraTerm にはどう打てばできるのか、具体的なソースコードを知りたいです。
発生している問題・エラーメッセージ
下記 該当のソースコード・実行の流れ にて、TeraTerm に次のメッセージが表示され解凍がされません。
TeraTerm
1[xxxxxxxxxxxx@sv11111 ~]$ unzip -d /home/xxxxxxxxxxxx/example.com/public_html/test.zip 2UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send 3bug reports using http://www.info-zip.org/zip-bug.html; see README for details. 4 5Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir] 6 Default action is to extract files in list, except those in xlist, to exdir; 7 file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage). 8 9 -p extract files to pipe, no messages -l list files (short format) 10 -f freshen existing files, create none -t test compressed archive data 11 -u update files, create if necessary -z display archive comment only 12 -v list verbosely/show version info -T timestamp archive to latest 13 -x exclude files that follow (in xlist) -d extract files into exdir 14modifiers: 15 -n never overwrite existing files -q quiet mode (-qq => quieter) 16 -o overwrite files WITHOUT prompting -a auto-convert any text files 17 -j junk paths (do not make directories) -aa treat ALL files as text 18 -U use escapes for all non-ASCII Unicode -UU ignore any Unicode fields 19 -C match filenames case-insensitively -L make (some) names lowercase 20 -X restore UID/GID info -V retain VMS version numbers 21 -K keep setuid/setgid/tacky permissions -M pipe through "more" pager 22 -O CHARSET specify a character encoding for DOS, Windows and OS/2 archives 23 -I CHARSET specify a character encoding for UNIX and other archives 24 25See "unzip -hh" or unzip.txt for more help. Examples: 26 unzip data1 -x joe => extract all files except joe from zipfile data1.zip 27 unzip -p foo | more => send contents of foo.zip via pipe into program more 28 unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
該当のソースコード・実行の流れ
圧縮するphpファイルはこちら test.php で、圧縮前は 171 バイトです。
php
1<?php 2 echo strlen('🏴'); 3 echo mb_strlen('🏴'); 4 echo grapheme_strlen('🏴'); 5?>
この test.php を Windows で「右クリック → 送る(N) → 圧縮(zip 形式)フォルダー」にて圧縮し、test.zip を生成しました。
そして test.zip を FileZilla でアップロードし、TeraTerm から次のコマンドを実行しました。
TeraTerm
1unzip -d /home/xxxxxxxxxxxx/example.com/public_html/test.zip
以上の流れで実行して 発生している問題・エラーメッセージ になります。
試したこと
試したこと1 (-l
で中身を確認)
-d
でなく-l
を試すと次のようになり、171 という Length も上述のように正しい値なので、ファイル自体はアクセスできているようです。
TeraTerm
1[xxxxxxxxxxxx@sv11111 ~]$ unzip -l /home/xxxxxxxxxxxx/example.com/public_html/test.zip 2Archive: /home/xxxxxxxxxxxx/example.com/public_html/test.zip 3 Length Date Time Name 4--------- ---------- ----- ---- 5 171 09-19-2022 06:58 test.php 6--------- ------- 7 171 1 file
試したこと2 (類似の状況の検索)
類似の状況を次のリンクで見つけました。上述のメッセージも同様に見えます。しかし、
unzipコマンドでzipファイルの解凍が出来ない
https://ja.stackoverflow.com/questions/57889/unzipコマンドでzipファイルの解凍が出来ない
ここには解決方法として次のようにありますが、これが理解できませんでした。
そのため、フルパスで/usr/bin/unzip を実行すれば、意図した通りにunzipが動作することが確認できました。
具体的に「では TeraTerm にどう打てばいいのか」をここから推察することができないためです。
例えばこう?↓とか…いえ、だめでした。(適当にこう書くくらいコマンドについて無知です。)
TeraTerm
1unzip -d /usr/bin/unzip test.zip
試したこと3 (圧縮過程の変更)
Windowsデフォルトでなく、7zipという圧縮ソフトを使って圧縮し、改めて上記の流れを実行しましたが、全て同じ結果でした。
補足情報(FW/ツールのバージョンなど)
Xserverのスタンダードプランを利用
FileZilla 3.60.2
CHERRY様よりご回答を受けて
CHERRY様よりオプション指定が不要とのアドバイスを頂戴し実行したところ、上記のような長いメッセージは表示されませんが、次のようにinflating
となりました。
TeraTerm
1[xxxxxxxxxxxx@sv11111 ~]$ unzip /home/xxxxxxxxxxxx/example.com/public_html/test.zip 2Archive: /home/xxxxxxxxxxxx/example.com/public_html/test.zip 3 inflating: test.php 4[xxxxxxxxxxxx@sv11111 ~]$ unzip /home/xxxxxxxxxxxx/example.com/public_html/test.zip -d ext_dir 5Archive: /home/xxxxxxxxxxxx/example.com/public_html/test.zip 6 inflating: ext_dir/test.php
そしてこれについて検索すると次のご質問を見つけまして
ZIP解凍時のinflatingとは?
https://okwave.jp/qa/q6601345.html
ご質問の状況では「> 解凍は無事に終わった」とありますが、私の状況では解凍自体がされていないようです。
( FileZilllla にてリロードしましたが test.php は見当たりませんし、ext_dir ディレクトリも自動で作成されていません。)
この後 public_html/ に ext_dir ディレクトリ を FileZilla で手動で作成してから再び次のように実行しましたら、replace の指定を要求されましたのでy
としたところ、やはりinflating
となりました。こちらも解凍はされておらず ext_dir ディレクトリは空のままでした。
TeraTerm
1[xxxxxxxxxxxx@sv11111 ~]$ unzip /home/xxxxxxxxxxxx/example.com/public_html/test.zip -d ext_dir 2Archive: /home/xxxxxxxxxxxx/example.com/public_html/test.zip 3replace ext_dir/test.php? [y]es, [n]o, [A]ll, [N]one, [r]ename: y 4 inflating: ext_dir/test.php

回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/09/19 00:07
2022/09/19 02:43 編集
2022/09/19 02:16