source: branches/feature-module-paygent/data/include/ftp.php @ 14676

Revision 14676, 2.7 KB checked in by adati, 14 years ago (diff)

1.4.0a-betaのマージ

Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7/*
8    $host:FTP¥Û¥¹¥È
9    $user:FTP¥æ¡¼¥¶
10    $pass:FTP¥Ñ¥¹¥ï¡¼¥É
11    $dst_file:Á÷¿®Àè¥Õ¥¡¥¤¥ë¡ÊÁêÂХѥ¹¡Ë
12    $src_file:Á÷¿®¸µ¥Õ¥¡¥¤¥ë¡ÊÀäÂХѥ¹¡Ë
13 */
14function sfFtpCopy($host, $user, $pass, $dst_file, $src_file) {
15    // FTPÀܳ
16    $conn_id = ftp_connect($host);
17
18    // Àܳ³Îǧ
19    if((!$conn_id)) {
20        gfPrintLog("FTPÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£SERVER:" . $host);
21        return;
22    }
23   
24    // FTP¥í¥°¥¤¥ó
25    $login_result = ftp_login($conn_id, $user, $pass);
26       
27    if ((!$login_result)) {
28        gfPrintLog("FTP¥í¥°¥¤¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£USER:" . $user . " SERVER:" . $host);
29        return;
30    }
31   
32    // Á÷¿®¸µ¥Õ¥¡¥¤¥ë¤Î¸ºß¥Á¥§¥Ã¥¯
33    if (is_file($src_file)) {
34       
35        // ¥Õ¥¡¥¤¥ëÁ÷¿®
36        $upload = ftp_put($conn_id, $dst_file, $src_file, FTP_BINARY);
37    } else {
38        gfPrintLog("FTPÁ÷¿®¸µ¥Õ¥¡¥¤¥ë¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡£" . $src_file);
39        return;
40    }
41   
42    // ¥Õ¥¡¥¤¥ë¥¢¥Ã¥×¥í¡¼¥É
43    if (!$upload) {
44        gfPrintLog("¥¢¥Ã¥×¥í¡¼¥É¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£SERVER:" . $host . " " . $src_file . " -> " . $dst_file);
45    } else {
46        gfPrintLog("¥¢¥Ã¥×¥í¡¼¥É¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£SERVER:" . $host . " " . $src_file . " -> " . $dst_file);
47    }
48
49    // Àܳ¤òÊĤ¸¤ë
50    ftp_close($conn_id);
51}
52
53function sfFtpDelete($host, $user, $pass, $dst_file) {
54    // FTPÀܳ
55    $conn_id = @ftp_connect($host);
56   
57    // Àܳ³Îǧ
58    if((!$conn_id)) {
59        gfPrintLog("FTPÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£SERVER:" . $host);
60        return;
61    }
62   
63    // FTP¥í¥°¥¤¥ó
64    $login_result = @ftp_login($conn_id, $user, $pass);
65   
66    if ((!$login_result)) {
67        gfPrintLog("FTP¥í¥°¥¤¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£USER:" . $user . " SERVER:" . $host);
68        return;
69    }
70       
71    // ¥Õ¥¡¥¤¥ëºï½ü
72    if (@ftp_delete($conn_id, $dst_file)) {
73        gfPrintLog("¥Õ¥¡¥¤¥ëºï½ü¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£SERVER:" . $host . " " . $dst_file);
74    } else {
75        gfPrintLog("¥Õ¥¡¥¤¥ëºï½ü¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£SERVER:" . $host . " " . $dst_file);
76    }
77   
78    // Àܳ¤òÊĤ¸¤ë
79    ftp_close($conn_id);
80}
81
82 /*
83 * ´Ø¿ô̾ ¡§sfFtpExist
84 * °ú¿ô1¡¡:FTP¥Û¥¹¥È
85 * $user:FTP¥æ¡¼¥¶
86 * $pass:FTP¥Ñ¥¹¥ï¡¼¥É
87 * $file_path:¥Õ¥¡¥¤¥ë¥Ñ¥¹
88 * Ìá¤êÃÍ¡§Â¸ºß¤·¤¿¤étrue̵¤«¤Ã¤¿¤éfalse¤òÊÖ¤¹
89 * ÀâÌÀ¡¡¡§FTP¤¹¤ë¥µ¡¼¥Ð¤Ë¥Õ¥¡¥¤¥ë¤¬Ìµ¤¤¤«Ä´ºº¤¹¤ë
90 */
91 function sfFtpExist($host, $user, $pass, $file_path) {
92
93    $conn_id = ftp_connect($host);
94    $login_result = ftp_login($conn_id, $user, $pass);
95    $res = ftp_size($conn_id, $file_path);
96
97    // Ìá¤êÃͤ¬-1¤Ê¤é¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤
98    if($res == -1) {
99        return false;
100    }
101       
102    return true;
103}
104?>
Note: See TracBrowser for help on using the repository browser.