반응형
OS : Window 10
Version : 2021.3.6f1
ftp서버에서 목록의 목록을 확인해야할 때, 사용하는 방법입니다.
웹 크롤링과 같은 원리로 생각하시면 될 것 같습니다
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using UnityEngine;
using static System.Net.WebRequestMethods;
public class CountFTPFile : MonoBehaviour
{
private void Start()
{
string uri = "http://192.168.20.160:8080/";
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
Regex regex = new Regex("<a href=\".*\">(?<name>.*)</a>");
Debug.Log("here");
using (var reader = new StreamReader(response.GetResponseStream()))
{
string result = reader.ReadToEnd();
Debug.Log(result);
MatchCollection matches = regex.Matches(result);
if (matches.Count == 0)
{
Debug.Log("parse failed.");
return;
}
foreach (Match match in matches)
{
if (!match.Success) { continue; }
Debug.Log(match.Groups["name"]);
}
}
}
}
위 소스코드 중에 Regex가 값을 받아오는 부분입니다.
왜냐하면 서버에서 html이 아래와 같은 형식이기 때문입니다.
new Regex("<a href=\".*\">(?<name>.*)</a>");
위 소스코드를 실행하면 다음과 같이 출력 됩니다
반응형
'유니티' 카테고리의 다른 글
C#을 사용하여 Unity 폴더의 파일 목록 가져오기 (0) | 2023.03.11 |
---|---|
유니티에서 URL을 통해 이미지 불러오기 (Loading Images from URL in Unity) (0) | 2023.03.07 |
ChatGPT 가라사대, 유니티 게임 엔진으로 게임 제작하기 (0) | 2023.03.03 |
PCG 기술을 사용한 유니티 RPG 게임 개발 - 1장 도전 문제? (0) | 2022.05.18 |
Unity Mesh Renderer Size (0) | 2022.05.16 |