{"id":2399,"date":"2015-07-16T23:31:23","date_gmt":"2015-07-16T14:31:23","guid":{"rendered":"http:\/\/taitan916.info\/blog\/?p=2399"},"modified":"2024-01-18T17:50:52","modified_gmt":"2024-01-18T08:50:52","slug":"post-2399","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/2399","title":{"rendered":"PHP\u3067\u4ed6\u30b5\u30fc\u30d0\u306bFTP\u7d4c\u7531\u306b\u3066\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>form\u3067\u9001\u4fe1\u3057\u305f\u5185\u5bb9\u3092\u30c1\u30a7\u30c3\u30af\u3057\u305f\u4e0a\u3067\u3001\u4ed6\u30b5\u30fc\u30d0\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u304b\u3063\u305f\u3002\u8abf\u3079\u305f\u3068\u3053\u308dFTP,HTTP\u304c\u4e3b\u529b\u3063\u307d\u3044\u3002FTP\u306e\u5834\u5408\u306f\u53d7\u4fe1\u5074\u306bFTP\u30b5\u30fc\u30d0\u304c\u5fc5\u8981\u3068\u306a\u308b\u304c\u3001\u53d7\u4fe1\u30c1\u30a7\u30c3\u30af\u7684\u306a\u3053\u3068\u306f\u884c\u308f\u306a\u304f\u3066\u826f\u3044\u306e\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u9001\u4fe1\u5074\u306e\u307f\u3002HTTP\u306e\u5834\u5408\u306f\u53d7\u4fe1\u5074\u306bFTP\u30b5\u30fc\u30d0\u306f\u3044\u3089\u306a\u3044\u304c\u3001\u9001\u53d7\u4fe1\u5171\u306b\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u5fc5\u8981\u3002\u3069\u3061\u3089\u3082\u8a66\u3057\u305f\u3051\u3069FTP\u306e\u65b9\u304c\u697d\u3060\u3063\u305f\u306e\u3067\u4ee5\u4e0b\u306b\u30bd\u30fc\u30b9\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>HTTP\u7d4c\u7531\u306e\u5834\u5408(2017\/03\/08\u8ffd\u8a18)<\/h2>\n<p>HTTP\u7d4c\u7531\u306e\u65b9\u6cd5\u3082\u8abf\u3079\u305f\u306e\u3067\u8ffd\u8a18\u3002<\/p>\n<p><a href=\"https:\/\/taitan916.info\/blog\/archives\/2728\" target=\"_blank\" rel=\"noopener\">https:\/\/taitan916.info\/blog\/archives\/2728<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/strong><\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nif( $_FILES['file']['size'] &gt; 0 ){\r\n    do{\r\n        $flg = false;\r\n        \/\/FTP\u30b5\u30fc\u30d0\u3068\u30a2\u30ab\u30a6\u30f3\u30c8\u60c5\u5831\r\n        $server = \"111.222.333.444\"; \/\/\u9001\u308a\u5148\u306eFTP\u30b5\u30fc\u30d0\u30fc\u540d\u3082\u3057\u304f\u306fIP\r\n        $user = \"xxxxxxxxxx\"; \/\/\u9001\u308a\u5148\u306eFTP\u30e6\u30fc\u30b6\r\n        $pass = \"xxxxxxxxxx\"; \/\/\u9001\u308a\u5148\u306eFTP\u30d1\u30b9\u30ef\u30fc\u30c9\r\n        $remoteDir = '.\/test\/'; \/\/\u9001\u308a\u5148\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\r\n        $localDir = '.\/tmp\/'; \/\/\u30ed\u30fc\u30ab\u30eb\u5074\u306e\u4e00\u6642\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\r\n        \/\/FTP\u30b5\u30fc\u30d0\u306b\u63a5\u7d9a\r\n        $ftp = ftp_connect($server);\r\n        if( !$ftp ) break;\r\n        \/\/\u30ed\u30b0\u30a4\u30f3\r\n        if( !ftp_login($ftp, $user, $pass) ) break;\r\n        \/\/FTP\u30b5\u30fc\u30d0\u4e0a\u3067\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u79fb\u52d5\r\n        if( !ftp_chdir($ftp, $remoteDir) ) break;\r\n        \/\/\u30ed\u30fc\u30ab\u30eb\u5074\u306b\u4e00\u5ea6\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\r\n        if( !move_uploaded_file($_FILES['file'][\"tmp_name\"], $localDir . $_FILES['file']['name']) ) break;\r\n        \/\/\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\r\n        $local = $localDir . $_FILES['file']['name']; \/\/\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u30d5\u30a1\u30a4\u30eb\r\n        $remote = $_FILES['file']['name']; \/\/\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6642\u306e\u540d\u524d\r\n        if( !ftp_put($ftp, $remote, $local, FTP_BINARY) ) break;\r\n        \/\/\u30ed\u30fc\u30ab\u30eb\u5074\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\r\n        unlink( $localDir . $_FILES['file']['name'] );\r\n        \/\/\u63a5\u7d9a\u3092\u9589\u3058\u308b\r\n        ftp_close($ftp);\r\n        $flg = true;\r\n    }while(0);\r\n    if( $flg ){\r\n        \/\/\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6210\u529f\u6642\u306e\u51e6\u7406\r\n    }else{\r\n        \/\/\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u5931\u6557\u6642\u306e\u51e6\u7406\r\n    }\r\n}\r\n?&gt;\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"ja\"&gt;\r\n&lt;head&gt;\r\n&lt;meta charset=\"utf-8\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;form action=\"&lt;?php echo $_SERVER['PHP_SELF'];?&gt;\" method=\"post\" enctype=\"multipart\/form-data\"&gt;\r\n    &lt;input type=\"file\" name=\"file\"&gt;&lt;br&gt;\r\n    &lt;input type=\"submit\" value=\"submit\"&gt;\r\n&lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-size: 14pt;\"><strong>\u305d\u306e\u4ed6<\/strong><\/span><\/h2>\n<p>VPS\u2192\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u3001VPS\u2192VPS\u9593\u3067\u30c1\u30a7\u30c3\u30af\u3057\u305f\u3068\u3053\u308d\u554f\u984c\u306a\u304b\u3063\u305f\u3002\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u2192\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u306f\u30c6\u30b9\u30c8\u74b0\u5883\u304c\u7121\u304b\u3063\u305f\u306e\u3067\u672a\u30c1\u30a7\u30c3\u30af\u3002<\/p>\n<p>HTTP\u3067\u9001\u308b\u5834\u5408\u306fcURL\u3067\u9001\u308b\u307f\u305f\u3044\u3002POST\u3067\u9001\u3063\u3066\u3001\u53d7\u3051\u53d6\u308a\u5074\u306f\u666e\u901a\u306bPHP\u3067\u53d7\u3051\u53d6\u308b\u3002<\/p>\n<p>\u3042\u3068\u3001\u3060\u3044\u3076\u524d\u306b\u898b\u305f\u30bd\u30fc\u30b9\u3067SSH\u3067\u9001\u3063\u3066\u3044\u305f\u30b1\u30fc\u30b9\u304c\u3042\u3063\u305f\u306e\u3067scp\u3067\u3084\u308d\u3046\u3068\u601d\u3063\u305f\u3093\u3060\u3051\u3069\u30d1\u30b9\u30ef\u30fc\u30c9\u5165\u529b\u306e\u7a81\u7834\u306e\u4ed5\u65b9\u304c\u5206\u304b\u3089\u306a\u304b\u3063\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>form\u3067\u9001\u4fe1\u3057\u305f\u5185\u5bb9\u3092\u30c1\u30a7\u30c3\u30af\u3057\u305f\u4e0a\u3067\u3001\u4ed6\u30b5\u30fc\u30d0\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u304b ... <\/p>\n","protected":false},"author":1,"featured_media":1085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2399","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/2399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=2399"}],"version-history":[{"count":0,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/2399\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1085"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=2399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=2399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=2399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}