久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用憑據連接 ftp 服務器

Connecting ftp server with credentials(使用憑據連接 ftp 服務器)
本文介紹了使用憑據連接 ftp 服務器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在編寫一個使用帶有憑據的 ftp 服務器的程序.我正在嘗試從服務器檢索目錄列表,但是當我到達線路時:

I'm writing a program that uses an ftp server with credentials. I'm trying to retrieve the directory list from the server but when I get to the line:

string line = reader.ReadLine();

我得到的字符串只包含:無法打開"host:/lib1"."

the string that I get contains only : "Can't open "host:/lib1"."

如果我嘗試獲取另一行,則會引發下一個異常:遠程服務器返回錯誤:(550) 文件不可用(例如,找不到文件,無法訪問).

If I try to get another line, the next exception is thrown: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

我確信(使用另一個 ftp 應用程序)'lib1' 目錄存在于 ftp 服務器上,并且我的憑據(用戶名和密碼)是正確的.

I know for sure (using another ftp application) that 'lib1' directory exists on the ftp server and my credentials (username and password) are correct.

這是我的代碼:

 public class FTPClient
{
    public string UserName { get; set; }
    public string Password { get; set; }
    public string IpAddress { get; set; }
    public int Port { get; set; }

    public FTPClient(string _userName, string _password, string _address, int _port)
    {
        UserName = _userName;
        Password = _password;
        IpAddress = _address;
        Port = _port;
    }

    public void GetDirectoriesList(string _path)
    {           
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + 
        IpAddress + _path));
        request.UseBinary = true;
        request.Method = WebRequestMethods.Ftp.ListDirectory;
        request.Credentials = new NetworkCredential(UserName, Password);

        FtpWebResponse response = (FtpWebResponse)request.GetResponse();
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(responseStream);

        string line = reader.ReadLine();
        while (line!=null)
        {
            ... //do something with line
            line = reader.ReadLine();
        }
        ...
        reader.Close();
        response.Close();


    }

我使用它如下:

FTPClient ftpClient = new FTPClient("user1", "pass1", "192.168.2.110", 21);

        string dirList = ftpClient.GetDirectoriesList("/lib1");

誰能發現問題?

推薦答案

我的解決方案:

public string[] GetDirectory()
{
    StringBuilder result = new StringBuilder();
    FtpWebRequest requestDir = (FtpWebRequest)WebRequest.Create("ftp://urserverip/");
    requestDir.Method = WebRequestMethods.Ftp.ListDirectory;
    requestDir.Credentials = new NetworkCredential("username", "password");
    FtpWebResponse responseDir = (FtpWebResponse)requestDir.GetResponse();
    StreamReader readerDir  = new StreamReader(responseDir.GetResponseStream());

    string line = readerDir.ReadLine();
    while (line != null)
    {
        result.Append(line);
        result.Append("
");
        line = readerDir.ReadLine();
    }

    result.Remove(result.ToString().LastIndexOf('
'), 1);
    responseDir.Close(); 
    return result.ToString().Split('
');
}

這篇關于使用憑據連接 ftp 服務器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 网站国产| 亚洲精品综合 | 中文天堂在线一区 | 国户精品久久久久久久久久久不卡 | 色综合久 | 成人福利在线视频 | 91在线视频免费观看 | 99免费在线| 日韩一级 | 最新中文字幕 | 国内自拍偷拍视频 | 欧美激情在线精品一区二区三区 | 一区二区成人 | www.国产.com| 97av视频在线 | 成人免费视频网 | 欧美久久电影 | 久久午夜影院 | 五月天婷婷丁香 | 亚洲精品日韩精品 | 中文字幕在线电影观看 | 91看片免费| 成人毛片一区二区三区 | 久久首页 | 久久免费精彩视频 | 日本视频一区二区三区 | 成人国产精品免费观看视频 | 亚洲一级在线 | 日韩视频精品在线 | 亚洲精品视频二区 | 五月天婷婷丁香 | 午夜影院在线视频 | 天啪 | 香蕉视频久久久 | 天天躁天天操 | 伊人精品国产 | 免费在线观看一区二区三区 | 涩涩视频网 | 亚洲精品一区二区三区四区高清 | 日韩av免费在线观看 | 日韩视频 中文字幕 |