【问题标题】:Chilkat connection exception in FTP2 in c#c#中FTP2中的Chilkat连接异常
【发布时间】:2012-05-10 17:58:42
【问题描述】:

我在 chilkat 异常中收到以下消息

  calling ConnectSocket2
    IPV6 enabled connect with NO heartbeat.
    Cannot connect, hostname is zero length
    ConnectFailReason: 1
    Failed to connect to FTP server.
    Failed.   --ConnectOnly_Ftp2
--ChilkatLog

我正在尝试使用 chilkat 的 Ftp2 类(使用 c#),使用 Connect 方法连接到 FTP 服务器。

以下是我用来连接 FTP2 的课程

   public class FTPClient
   {        
    private Ftp2 m_FtpInfo;

    const int FTP_DEFAULT_PORT = 21;

    public FTPClient()
    {
        m_FtpInfo = null;
    }

    public FTPClient(string userName, string password, string hostName, int port)
    {
        m_FtpInfo = new Ftp2();
        m_FtpInfo.Account = userName;
        m_FtpInfo.ClientIpAddress = hostName;
        m_FtpInfo.Password = password;
        //m_FtpInfo.Port = port;
    }

    public Ftp2 FTPInfo
    {
        get
        {
            if (m_FtpInfo == null)
                m_FtpInfo = new Ftp2();
            return m_FtpInfo;
        }
        set { m_FtpInfo = value; }
    }

    public void Connect()
    {
        lock (this)
        {
            if (m_FtpInfo == null)
            {
                m_FtpInfo = new Ftp2();
            }

            AppConfiguration appConfiguration = AppConfiguration.Instance;
            /*
             * Steps to connect to FTP site using Chilkat
             * 1. Unlock the component by passing the code provided by Chilkat
             * 2. Connect to the Site by specifying the hostname and port
             */

            // Unlock the component.
            if (!m_FtpInfo.UnlockComponent("AnythingWorksFor30DayTrial"))
            {
                throw new FTPConnectionExceptions(CommunicationError.UnlockFailed, m_FtpInfo.LastErrorText);
            }


            // Connect to the FTP server. (use a domain name or IP address)            
            if (!m_FtpInfo.Connect())
            {
                throw new FTPConnectionExceptions(CommunicationError.ConnectionFailed, m_FtpInfo.LastErrorText);
            }
        }
    }

    public void DisposeConnection()
    {
        lock (this)
        {
            if (m_FtpInfo == null) return;

            if (m_FtpInfo.IsConnected)
                m_FtpInfo.Disconnect();

            m_FtpInfo = null;
        }
    }

谁能告诉我哪里出错了?

【问题讨论】:

  • 错误Cannot connect, hostname is zero length 可能意味着您忘记设置目标服务器。能否提供一些代码(创建实例、设置属性、调用连接等)?
  • 我已经编辑了我的帖子以提供使用 FTP 连接的课程详细信息

标签: c# chilkat


【解决方案1】:

m_FtpInfo.ClientIpAddress = hostName; 行不是必需的。实际连接的主机没有设置。

编辑:

Chilkat 示例页面这样设置主机名:

ftp.Hostname = "ftp.chilkatsoft.com";

所以不要设置 ClientIpAddress(本地 PC 的 ip),而是使用 Hostname。

编辑 2:

试试这个:

public FTPClient(string userName, string password, string hostName, int port)
{
    m_FtpInfo = new Ftp2();
    m_FtpInfo.Account = userName;
    m_FtpInfo.Hostname = hostName;
    m_FtpInfo.Password = password;
    //m_FtpInfo.Port = port;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-03
    • 1970-01-01
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多