4

FTP サーバーにアクセスし、ディレクトリの下にあるファイルのリストを取得するスクリプトがあります。

//line 65 of Status script that is mentioned in error message
string[] list = ftp.DirectoryListSimple("AdvancedCalender/Calenders/Versions");
//ftp.DirectoryListSimple()
//FTP script that is mentioned in error message
public string[] DirectoryListSimple(string directory)
{
    try
    {
        Uri serverUri = new Uri(host);
        Uri relativeUri = new Uri("/" + directory);
        Uri fullUri = new Uri(serverUri, relativeUri);
        ftpRequest = (FtpWebRequest)FtpWebRequest.Create(fullUri);

        ftpRequest.Credentials = new NetworkCredential(user, pass);

        ftpRequest.UseBinary = true;
        ftpRequest.UsePassive = true;
        ftpRequest.KeepAlive = true;

        ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;

        ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();

        ftpStream = ftpResponse.GetResponseStream();

        StreamReader ftpReader = new StreamReader(ftpStream);

        string directoryRaw = null;

        try { while (ftpReader.Peek() != -1) { directoryRaw += ftpReader.ReadLine() + "|"; } }
        catch (Exception ex) { Debug.LogError(ex.ToString()); }

        ftpReader.Close();
        ftpStream.Close();
        ftpResponse.Close();
        ftpRequest = null;

        try { string[] directoryList = directoryRaw.Split("|".ToCharArray()); return directoryList; }
        catch (Exception ex) { Debug.LogError(ex.ToString()); }
    }
    catch (Exception ex) { Debug.LogError(ex.ToString()); }
    //^ error caught here
    return new string[] { "" };
}

エラーメッセージ:

System.UriFormatException: 無効な URI: URI の形式を特定できませんでした。System.Uri.CreateThis (System.String uri、System.Boolean dontEscape、System.UriKind uriKind) [0x0007b] で:0 System.Uri..ctor (System.String uriString) [0x00014] で:0 BtStudios で。 HelperClasses.FtpHelpers.FTP.DirectoryListSimple (System.String ディレクトリ) [0x0000b] in C:\Users\btowr\OneDrive\Desktop\Advanced Calender\Assets\FTP.cs:299 UnityEngine.Debug:LogError (オブジェクト) BtStudios.HelperClasses. FtpHelpers.FTP:DirectoryListSimple (文字列) (Assets/FTP.cs:330 で) Status:Start () (Assets/Status.cs:65 で)

FTP サーバーに接続できること、ファイルが存在すること、URI 形式が正しいこと (少なくとも私が知っていること) を確認できます。

(編集)関数で使用されている変数を表示する必要がある場合は、共有できますが、IP、ユーザー名、パスワードなどの機密情報は、実際の IP ユーザー名とパスワードと同じではありません。

4

1 に答える 1