[완료] ftp client를 만들고 있는데 조언 구합니다.

cyu0070의 이미지

ftp 클라이언트를 구현하고 있는데 도움요청드립니다

먼저 서버는 구현다되었고요
클라이언트를 구현해야하는데 잘몰라서 도움요청드립니다

dir명령어를 클라이언트에서 실행하려면 먼저

프롬프트 dir
dir 구현코드

클라이언트가 서버에게 PORT명령어를 보냄
리턴 결과값 받음
클라이언트가 서버에게 LIST명령어를 보냄

디렉토리 정보를 select하여 받음

write(sock,"PORT 127,0,0,1,231,167\r\n",strlen("PORT 127,0,0,1,231,167\r\n")+1);	
 
이렇게 보내는걸로 알고있습니다.
 
 
이렇게 해서 로컬호스트상에서는 아무문제 없이 동작을 하지만
 
다른컴퓨터에서 하니 안되는군요
 
앞에 4자리는 ip를 가지고 오는것은 맞는데  뒤에 2자리가 먼지 궁금합니다.
 
 
그리고 이 ip정보가 client 의 ip인지 server의 ip인지 궁금하네요 로컬호스트다보니 궁금합니다

violino의 이미지

아무도 대답을 안하는 것 같아서, 찾아서 답변드립니다.

PORT
Syntax: PORT a1,a2,a3,a4,p1,p2

Specifies the host and port to which the server should connect for the next file transfer. This is interpreted as IP address a1.a2.a3.a4, port p1*256+p2.

(출처: http://www.nsftools.com/tips/RawFTP.htm)

말그대로 p1과 p2가 합쳐서 포트넘버입니다. p1은 상위 바이트, p2는 하위 바이트가 되겠죠?

PS> RFC959 문서에는 (http://www.w3.org/Protocols/rfc959/8_PortNumber.html) 자세히 설명은 안되어 있고, 그냥 6개중에서 첫번째 바이트가 상위라고만 되어있네요. 이런데 익숙한 사람들이야 이해하겠지만, 일반인들이 헷갈리기 쉽겠네요.

cyu0070의 이미지

저도 PORT에 대한 자료를 찾다가 Specifies the host and port to which the server should connect for the next file transfer. This is interpreted as IP address a1.a2.a3.a4, port p1*256+p2 이 문장을 보았습니다.

답변은 감사하지만 p1,p2 에 대한 내용이 이해가 잘안갑니다...

예를 들어 데이터 포트 9999라고 가정을 하면 상위 바이트와 하위 바이트로 나눠서 상위에 256으로 곱해야겠지요 그리고 p2를 더해준다고 나와있습니다.

그럼 9999 라고 할때 p1과 p2는 9999/256 = 39 나머지가 19니깐

p1은 39 와 p2는 19가 되는것인가요?

violino의 이미지

예, 그렇습니다.
16진수로 생각하시면 더욱 이해가 빠르실겁니다.
그냥 두바이트 합쳐서 16진수의 네자리 숫자를 써 놨다고 생각하시면 됩니다.
말씀하신 예에서 십진수 9999는 16진수 270F 이므로,
p1=0x27, p2=0x0F 가 되는 거지요.
도움이 되셨으면 합니다.

vio:

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.