알아두면 좋은 IT 지식/Network

curl post json http telnet sftp 명령어 사용법 옵션 예제

uutopia 2022. 2. 7. 13:18

CURL 지원 프로토콜

DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP,  LDAPS,  POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP

 

TELNET

TELNET 예제

curl -v 'telnet://[IP]:[PORT]'

 

[user@host ~]$ curl -v telnet://10.0.2.16:8089
* About to connect() to 10.0.2.16 port 8089 (#0)
*   Trying 10.0.2.16...
* Connected to 10.0.2.16 (10.0.2.16) port 8089 (#0)

 

HTTP

GET 예제

curl -v -X GET 'http://[IP]:[PORT]/[URL]?[PARAMETER]'

 

[user@host ~]$ curl -v -X GET 'http://10.0.2.16:8089/http/test01?key1=1&key2=2'
* About to connect() to 10.0.2.16 port 8089 (#0)
*   Trying 10.0.2.16...
* Connected to 10.0.2.16 (10.0.2.16) port 8089 (#0)
> GET /http/test01?key1=1&key2=2 HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 10.0.2.16:8089
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 07 Feb 2022 04:14:59 GMT
< Content-Type: */*;charset=UTF-8
< Transfer-Encoding: chunked
<
* Connection #0 to host 10.0.2.16 left intact
key1=1&key2=2

 

POST 예제

curl -v -X POST -H '[HTTP HEADER]' 'http://[IP]:[PORT]/[URL]' -d '[DATA]'

 

[user@host ~]$ curl -v -X POST -H 'Content-type:application/json' 'http://10.0.2.16:8089/http/test01' -d '{"key1":{"key11":"value11","key12":"value12"},"key2":{"key21":"value21"}}'
* About to connect() to 10.0.2.16 port 8089 (#0)
*   Trying 10.0.2.16...
* Connected to 10.0.2.16 (10.0.2.16) port 8089 (#0)
> POST /http/test01 HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 10.0.2.16:8089
> Accept: */*
> Content-type:application/json
> Content-Length: 73
>
* upload completely sent off: 73 out of 73 bytes
< HTTP/1.1 200 OK
< Date: Mon, 07 Feb 2022 04:08:21 GMT
< Content-Type: */*;charset=UTF-8
< Transfer-Encoding: chunked
<
* Connection #0 to host 10.0.2.16 left intact
{"key1":{"key11":"value11","key12":"value12"},"key2":{"key21":"value21"}}You have new mail in /var/spool/mail/anylink

 

SFTP

SFTP 예제

curl -v -k 'sftp://[IP]:[PORT]/[SRC FILE PATH]' -u '[USER]:[PASS]' -o '[TGT FILE PATH]' --ftp-create-dirs

 

[user@host ~]$ curl -v -k 'sftp://10.0.2.16/home/user/test.txt' -u 'username:password' -o '/home/user/test.txt' --ftp-create-dirs
* About to connect() to 10.0.2.16 port 22 (#0)
*   Trying 10.0.2.16...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 10.0.2.16 (10.0.2.16) port 22 (#0)
* SSH MD5 fingerprint: uab58479d713020b59e910b610c9cad3
* SSH authentication methods available: publickey,password
* Using SSH private key file ''
* SSH public key authentication failed: Unable to extract public key from private key file: Unable to open private key file
* Initialized password authentication
* Authentication complete
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0{ [data not shown]
100  400M  100  400M    0     0  26.7M      0  0:00:14  0:00:14 --:--:-- 33.7M
100  400M  100  400M    0     0  26.7M      0  0:00:14  0:00:14 --:--:-- 26.7M
* Connection #0 to host 10.0.2.16 left intact