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

使用憑據(jù)連接 ftp 服務(wù)器

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

問題描述

限時送ChatGPT賬號..

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

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"."

如果我嘗試獲取另一行,則會引發(fā)下一個異常:遠(yuǎn)程服務(wù)器返回錯誤:(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 應(yīng)用程序)'lib1' 目錄存在于 ftp 服務(wù)器上,并且我的憑據(jù)(用戶名和密碼)是正確的.

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");

誰能發(fā)現(xiàn)問題?

推薦答案

我的解決方案:

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('
');
}

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

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

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應(yīng)用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應(yīng)用程序在通過管理門戶更新之前無法運(yùn)行)
主站蜘蛛池模板: 青青操av| 人成在线 | 国产免费一区二区 | 黄色高清视频 | 欧美国产日韩在线观看 | 99综合网| 国产乱一区二区三区视频 | 欧美lesbianxxxxhd视频社区 | 羞羞视频免费在线 | 精品久久久久久亚洲精品 | 日韩久久精品 | 日日操日日舔 | 国产免费一区二区三区 | 亚洲成av人影片在线观看 | 国产精品日韩欧美一区二区三区 | av在线播放不卡 | 91精品国产乱码久久久 | av影音资源| 成人精品在线观看 | 在线国产一区二区 | 一区精品视频在线观看 | 欧美乱大交xxxxx另类电影 | 日韩在线精品视频 | 国产成人精品免高潮在线观看 | 国产精品久久久久久影院8一贰佰 | 成年人精品视频 | 免费观看一级黄色录像 | 九色视频网 | a级免费观看视频 | 久草视频在线播放 | 狠狠色香婷婷久久亚洲精品 | 免费激情网站 | 日韩一区二区三区视频在线播放 | 国产激情视频在线免费观看 | 操操操日日日 | 欧美综合视频在线 | 精品欧美一区二区精品久久久 | 久久久精品一区二区 | 伊人网站| 99久久99热这里只有精品 | 免费观看a级毛片在线播放 黄网站免费入口 |