1

我有一个当前的连接方法

    ftp ftpClient = new ftp(@"ftp://testftp/", @"username", @"password", false);
string[] dirlist = ftpClient.directoryListSimple("/");
            foreach (var x in dirlist) { Console.WriteLine(x); }
            Console.ReadKey();

这是 FTP 类的目录列表的代码

      public class ftp
    {
        private string host = null;
        private string user = null;
        private string pass = null;
        private FtpWebRequest ftpRequest = null;
        private FtpWebResponse ftpResponse = null;
        private Stream ftpStream = null;
        private int bufferSize = 2048;
        private bool enableSSL = true;
/* List Directory Contents File/Folder Name Only */
    public string[] directoryListSimple(string directory)
    {
        try
        {
            /* Create an FTP Request */
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + directory);
            /* Log in to the FTP Server with the User Name and Password Provided */
            ftpRequest.Credentials = new NetworkCredential(user, pass);
            /* When in doubt, use these options */
            ftpRequest.UseBinary = true;
            ftpRequest.UsePassive = false;
            ftpRequest.KeepAlive = true;
            /* EnableSSL if required, most times false */
            ftpRequest.EnableSsl = enableSSL;
            /* Specify the Type of FTP Request */
            ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
            /* Establish Return Communication with the FTP Server */
            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            /* Establish Return Communication with the FTP Server */
            ftpStream = ftpResponse.GetResponseStream();
            /* Get the FTP Server's Response Stream */
            StreamReader ftpReader = new StreamReader(ftpStream);
            /* Store the Raw Response */
            string directoryRaw = null;
            /* Read Each Line of the Response and Append a Pipe to Each Line for Easy Parsing */
            try { while (ftpReader.Peek() != -1) { directoryRaw += ftpReader.ReadLine() + "|"; } }
            catch (Exception ex) { Console.WriteLine(ex.ToString()); }
            /* Resource Cleanup */
            ftpReader.Close();
            ftpStream.Close();
            ftpResponse.Close();
            ftpRequest = null;
            /* Return the Directory Listing as a string Array by Parsing 'directoryRaw' with the Delimiter you Append (I use | in This Example) */
            try { string[] directoryList = directoryRaw.Split("|".ToCharArray()); return directoryList; }
            catch (Exception ex) { Console.WriteLine(ex.ToString()); }
        }
        catch (Exception ex) { Console.WriteLine(ex.ToString()); }
        /* Return an Empty string Array if an Exception Occurs */
        return new string[] { "" };
    } 
}

然后我尝试运行一个目录列表,它在测试设置中完美运行。
但是,当我和我们的一个合作伙伴一起去时,我得到了我在 Chrome 中测试的530 Not Logged In
并且它登录良好并显示了我尝试使用 SSL 的目录列表
,没有,主动,被动无济于事
我能做的最后一件事想想他们提供了一个别名,但我不知道它会去哪里。在谷歌上,他们说要进行 testftp|alias,但由于 URI 格式的原因,这不起作用
任何对此的帮助将不胜感激

4

1 回答 1

1

找到我的答案,
出于某种原因,即使我已将其设置为 false,它仍试图建立 SSL 连接。注释掉该行已允许连接

于 2013-10-21T12:30:47.620 回答