[英]Chilkat connection exception in FTP2 in c#
I am getting the following message in the chilkat exception 我在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
I am trying to connect to FTP server using chilkat's Ftp2 class(using c#), using Connect method. 我正在尝试使用Connect方法使用chilkat的Ftp2类(使用c#)连接到FTP服务器。
Following is my class which I am using to connect with the FTP2 以下是我用来连接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;
}
}
Can anyone please tell where am I going wrong? 谁能告诉我我要去哪里错了?
The line m_FtpInfo.ClientIpAddress = hostName;
行
m_FtpInfo.ClientIpAddress = hostName;
isn't required. 不需要。 The actual host to connect to isn't set.
未设置要连接的实际主机。
Edit: 编辑:
The Chilkat example page sets the hostname like this: Chilkat示例页面按如下所示设置主机名:
ftp.Hostname = "ftp.chilkatsoft.com";
So instead of setting ClientIpAddress (the local PC's ip), use Hostname. 因此,不要设置ClientIpAddress(本地PC的IP),而要使用主机名。
Edit 2: 编辑2:
Try this: 尝试这个:
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.