FTP PORT 명령

IT/Programming/Solution/Tip 2014. 10. 30. 17:09

* IIS FTP(파일 전송 프로토콜) 서비스에 대한 정보 ( http://support.microsoft.com/kb/283679/ko ) 에서 발췌하였다.

 

 

 

IIS 기반 FTP 서비스(MSFTPSVC)는 클라이언트가 지정하는 방식에 따라 active 모드와 passive 모드 연결을 모두 지원합니다. IIS는 RFC 959에 이러한 기능이 결여되어 있어 active 모드나 passive 모드 연결 중 하나를 비활성화하는 것을 지원하지 않습니다. 인터넷에 사용되는 HTTP 및 대부분의 다른 프로토콜과 달리 FTP 프로토콜은 세션 동안 최소 두 개의 연결을 사용합니다. 즉, 제어를 위해 반이중 연결을 사용하고 데이터 전송을 위해 전이중 연결을 사용합니다. 기본적으로 TCP 포트 21은 제어 연결을 위해 서버에서 사용되지만 데이터 연결은 클라이언트가 서버에 연결하는데 사용하는 방식에 따라 결정됩니다.

active 모드 FTP 연결

active 모드 FTP는 클라이언트가 제어 연결을 통해 PORT 명령을 서버에 보내 서버의 PORT 명령에서 지정하는 TCP 포트를 사용하여 TCP 포트 20에서 클라이언트로 데이터 연결을 설정하도록 서버에 요구하기 때문에 "클라이언트 관리"라고도 합니다.

FTP 클라이언트는 다음과 같은 형식으로 PORT 명령을 FTP 서버로 보냅니다.

PORT 192,168,0,3,19,243

 

여기서 처음 4개의 쉼표로 구분된 값은 클라이언트 IP 주소의 옥텟에 해당하며 5번째와 6번째 값은 16비트 포트 번호의 상위 비트와 하위 비트입니다. 상위 비트와 하위 비트를 (십진수) 포트 번호로 변환하려면 5번째 값에 256을 곱하여 6번째 값에 더하면 됩니다. 위의 예에서 TCP 포트(십진수)는 (256 x 19) + 243 = 5107이므로 클라이언트는 192.168.0.3:5107로 데이터 연결을 열도록 서버에 지시하게 됩니다. 기본적으로 FTP 클라이언트는 데이터 연결 포트로 임시 포트를 선택합니다. 임시 포트는 1024와 65535 사이의 사용 가능한 포트 중에서 임의로 선택된 포트입니다.

참고: Windows NT 4.0과 Windows 2000에서 유효한 기본 임시 포트 범위는 1024-5000입니다. Windows NT 4.0과 Windows 2000에서 임시 포트 범위를 늘리려면 시스템 레지스트리에 값을 추가해야 합니다.

설정

트랙백

댓글

(PHP) isset() vs empty() vs is_null()

IT/Programming/PHP 2014. 10. 29. 15:16

isset(), empty(), is_null() 은 모두 해당 변수에 값이 들어있는지 안들어있는지를 체크하는 함수이다.

하지만 이 3가지 함수 모두 <비어있다> 를 판단하는 기준이 서로 조금씩 달라 혼선이 생길 수 있다.

 

아래의 테이블을 참고하도록 한다.

 

 

PHP 5.3.8 기준으로 테스트되었다.

비어있는 칸은 bool(false) 를 의미한다.

 

 

 

 

 

 

PHP Manual

isset() - http://php.net/manual/en/function.isset.php

empty() - http://php.net/manual/en/function.empty.php

is_null() - http://php.net/manual/en/function.is-null.php

 

참고 링크 :

https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/

 

 

설정

트랙백

댓글

(PHP) $_SERVER['REMOTE_ADDR'] 이 ::1 을 반환할 때

IT/Programming/PHP 2014. 10. 22. 13:33

PHP 에서 $_SERVER['REMOTE_ADDR'] 이 ::1 을 반환하는 경우가 있다.

이는 IPv6 에서의 자기 자신을 가리키는 loopback address 이다. 즉, IPv4 의 127.0.0.1 과 똑같은 주소라고 보면 된다.

 

이를 해결하기 위해서는 IPv4 인터페이스로 사이트를 접속하거나 (이를테면 http://localhost/ 가 아닌 http://127.0.0.1/), 바인딩하는 호스트의 정보를 IPv4 형식으로 바꾸면 된다. 이 포스트에서는 Apache의 httpd.conf의 사이트 바인딩 정보 수정, IIS 사이트 바인딩 정보 수정, hosts 파일의 정보 수정, inet_ntop() 함수를 이용한 컨버팅 4가지의 해결방법을 소개한다.

 

 

Apache의 경우 :

httpd.conf 에서 Listen 항목을 찾아본다.

Listen 80  과 같이 적혀있다면, Listen 127.0.0.1:80  의 형식으로 변경하고 Apache를 재시작한다.

 

IIS의 경우 :

 

 

IIS(인터넷 정보 서비스) 관리자를 열고, 사이트 항목에 들어가보면 자신이 열어놓은 웹 사이트의 바인딩 정보를 볼 수 있다. 지금은 필자가 이미 127.0.0.1:80 으로 바인딩을 해둔 상태이지만, 지금 문제가 발생하고 있는 독자들은 아마도 :80 (http) 로 바인딩 되어 있을 것이다. 해당 항목을 오른쪽 클릭 - 바인딩 메뉴를 누르자.

 

 

편집(E) 를 눌러 IP 주소 항목에 127.0.0.1 을 작성하고 확인한 후, 사이트를 재시작하거나 IIS 를 재시작하면 문제는 해결된다.

 

 

hosts 파일 수정 :

hosts 파일을 찾아서 localhost 를 127.0.0.1 로 대응시켜주는 구문을 넣어주면 된다. 아래의 구문을 참고한다.

127.0.0.1       localhost  

 

 

설정

트랙백

댓글

[XE] 흰 페이지만 보일 때 && 1.5 버젼 이후 모듈 사용 주의사항

IT/Programming/PHP 2014. 9. 14. 18:24

제로보드 XE 에서 1.5 버젼 이전에 사용하던 모듈이 1.5 버젼 이후의 버젼으로 코어를 업데이트 했을 때 모듈들이 아무것도 없는 화면을 보이면서 페이지가 작동을 하지 않는 문제가 발생하고 있다.

 

이는 1.5 버젼 이후부터 __ZBXE__ 스위치가 __XE__ 로 변경되었기 때문이다.

다음의 패치 이슈를 참고 하도록 하자. : 

Issue 2607:

독립 php 페이지에서 세션공유시

   http://code.google.com/p/xe-core/issues/detail?id=2607

 

config.inc.php 를 XE 세션 공유를 위하여 require() 등으로 가져올 때, 아래의 구문에 의하여 exit() 이 되어버린다.

 

    if(!defined('__XE__'))
    {
     exit();

    }

 

기존에 사용하던 모듈(지금 문제가 발생하고 있는 모듈) 의 소스코드를 보면 아래와 같이 define이 되어있는 구문이 있을 것이다.

define('__ZBXE__',true);

 

define('__XE__', true); 구문을 require() 로 config.inc.php 를 가져오기 전에 추가해주면 해당 문제는 해결된다.

 

ex)

// Define XE Module
define('__ZBXE__',true);
define('__XE__',true);           // 추가
require_once("./config/config.inc.php");

 

 

다만, 이를 사용하는 다른 페이지가 있을 수 있으니 기존에 사용하던 __ZBXE__ 문은 삭제하지 않도록 하자. (호환성의 문제가 있을 수 있으니..)

 

** 물론, config.inc.php 를 수정하여 __XE__ 를 define 해주는 등 전역으로 문제를 해결할 수 있는 방법이 있긴 하지만, __ZBXE__가 __XE__ 로 변경되는 것은 공식적인 사항이므로 모듈 페이지를 손을 보는 것이 올바르다.

** 그리고 config.inc.php 와 같은 전역적으로 사용하는 페이지는 수정하지 않는 것이 바람직하다. 또한, xe 패치 시 자동으로 패치가 이루어지는 페이지이기도 하니 되도록이면 손을 대지 않도록 하자.

 

 

설정

트랙백

댓글

Unix Time Stamp(epoch) 구하기

IT/Programming/Programming 2014. 8. 26. 11:06

우선 아주 훌륭한 사이트를 소개한다.

http://www.epochconverter.com/

http://www.unixtimestamp.com/index.php

 

epochconverter.com 에서 각 언어별 예제를 상세하게 알아볼 수 있다.

더불어 epoch<->current time converter 까지 각 언어 별로 제공한다.

 

그 예시를 아래에 포스트한다.

 

How to get the current epoch time in ...

PHP time() more ...
Python import time first, then time.time()
Ruby Time.now (or Time.new). To display the epoch: Time.now.to_i
Perl time more ...
Java long epoch = System.currentTimeMillis()/1000;
C# var epoch = (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
Objective-C [[NSDate date] timeIntervalSince1970]; (returns double) or NSString *currentTimestamp = [NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]];
C++11 double now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
VBScript/ASP DateDiff("s", "01/01/1970 00:00:00", Now())
AutoIT _DateDiff('s', "1970/01/01 00:00:00", _NowCalc())
Delphi Epoch := DateTimetoUnix(Now); Tested in Delphi 2010.
R as.numeric(Sys.time())
Erlang calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600.
MySQL SELECT unix_timestamp(now()) more ...
PostgreSQL SELECT extract(epoch FROM now());
SQLite SELECT strftime('%s', 'now');
Oracle PL/SQL SELECT (SYSDATE - TO_DATE('01/01/1970 00:00:00', 'MM-DD-YYYY HH24:MI:SS')) *
24 * 60 * 60 FROM DUAL
SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
JavaScript Math.round(new Date().getTime()/1000.0) getTime() returns time in milliseconds.
Visual FoxPro DATETIME() - {^1970/01/01 00:00:00} Warning: time zones not handled correctly
Adobe ColdFusion <cfset epochTime = left(getTickcount(), 10)>
Tcl/Tk clock seconds
Unix/Linux Shell date +%s
PowerShell get-date (get-date).touniversaltime() -uformat "%s"
Other OS's

Command line: perl -e "print time" (If Perl is installed on your system)

 

Convert from human readable date to epoch

PHP strtotime("15 November 2012") (converts most English date texts) or:
date_create('01/15/2010')->format('U') (PHP5 DateTime class) more ...
Python import time first, then int(time.mktime(time.strptime('2000-01-01 12:34:00', '%Y-%m-%d %H:%M:%S'))) - time.timezone
Ruby Time.local(year, month, day, hour, minute, second, usec ) (or Time.gm for GMT/UTC input). To display add .to_i
Perl Use the Perl Epoch routines
Java long epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000;
VBScript/ASP DateDiff("s", "01/01/1970 00:00:00", time field) More info
AutoIT _DateDiff('s', "1970/01/01 00:00:00", "YYYY/MM/DD HH:MM:SS")
Delphi Epoch := DateTimeToUnix(StrToDateTime(myString));
C Use the C Epoch Converter routines
R as.numeric(as.POSIXct("MM/dd/yyyy HH:mm:ss", origin="1970-01-01"))
MySQL SELECT unix_timestamp(time) Time format: YYYY-MM-DD HH:MM:SS or YYMMDD or YYYYMMDD
More on using Epoch timestamps with MySQL
PostgreSQL SELECT extract(epoch FROM date('2000-01-01 12:34'));
With timestamp: SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-08');
With interval: SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
SQLite SELECT strftime('%s',timestring);
SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', time field)
JavaScript Use the JavaScript Date object
Unix/Linux Shell date +%s -d"Jan 1, 1980 00:00:01" Replace '-d' with '-ud' to input in GMT/UTC time.

 

Convert from epoch to human readable date

PHP date(output format, epoch); Output format example: 'r' = RFC 2822 date more ...
Python import time first, then time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(epoch)) Replace time.localtime with time.gmtime for GMT time. More info
Ruby Time.at(epoch)
Perl Use the Perl Epoch routines
Java String date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (epoch*1000));
VBScript/ASP DateAdd("s", epoch, "01/01/1970 00:00:00") More info
AutoIT _DateAdd("s", $EpochSeconds , "1970/01/01 00:00:00")
Delphi myString := DateTimeToStr(UnixToDateTime(Epoch)); Where Epoch is a signed integer.
C Use the C Epoch Converter routines
Objective-C NSDate * myDate = [NSDate dateWithTimeIntervalSince1970:epoch]; NSLog(@"%@", date);
R as.POSIXct(epoch, origin="1970-01-01", tz="GMT")
MySQL FROM_UNIXTIME(epoch, optional output format) Default output format is YYY-MM-DD HH:MM:SS. If you need support for negative timestamps: DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), interval -315619200 second),"%Y-%m-%d") (replace -315619200 with epoch) more ...
PostgreSQL PostgreSQL version 8.1 and higher: SELECT to_timestamp(epoch); More info Older versions: SELECT TIMESTAMP WITH TIME ZONE 'epoch' + epoch * INTERVAL '1 second';
SQLite SELECT datetime(epoch_to_convert, 'unixepoch'); or local timezone: SELECT datetime(epoch_to_convert, 'unixepoch', 'localtime');
Oracle PL/SQL SELECT to_date('01-JAN-1970','dd-mon-yyyy')+(1326357743/60/60/24) from dual
Replace 1326357743 with epoch.
SQL Server DATEADD(s, epoch, '1970-01-01 00:00:00')
Microsoft Excel =(A1 / 86400) + 25569 Format the result cell for date/time, the result will be in GMT time (A1 is the cell with the epoch number). For other time zones: =((A1 +/- time zone adjustment) / 86400) + 25569.
Crystal Reports DateAdd("s", {EpochTimeStampField}-14400, #1/1/1970 00:00:00#) -14400 used for Eastern Standard Time. See Time Zones.
JavaScript Use the JavaScript Date object
Tcl/Tk clock format 1325376000 More info
Unix/Linux Shell date -d @1190000000 Replace 1190000000 with your epoch, needs recent version of 'date'. Replace '-d' with '-ud' for GMT/UTC time.
PowerShell Function get-epochDate ($epochDate) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($epochDate)) }, then use: get-epochDate 1279152364. Works for Windows PowerShell v1 and v2
Other OS's Command line: perl -e "print scalar(localtime(epoch))" (If Perl is installed) Replace 'localtime' with 'gmtime' for GMT/UTC time.

설정

트랙백

댓글