sfFTPLib.enumError.ftpErrorTimeout Error

I've just downloaded and installed the FTP library. I modified the c# sample code for SFTP to use our real ftp host, port, username and password. When execute line sfFTPLib.enumError err = _connection.Connect(), I always got an error 'sfFTPLib.enumError.ftpErrorTimeout'. This connection works in SmartFTP client.

Is this because I don't have a valid license or something else? And how can I get a trial license to evaluate?

Thanks in advance.

Set LogFile property and then post the log here.

Thanks for the reply. Here is the log file. It says timeout, but it's very fast if I connect through SmartFTP client. This ftp is samrt ftps

host name: 75.126.59.170
port: 21
username = anonymous
password is empty

---log file---

[20110602 15:01:23] SmartFTP FTP Library 2.0.118.0
[20110602 15:01:23] Resolving host name "75.126.59.170"
[20110602 15:01:23] Connecting to 75.126.59.170 Port: 21
[20110602 15:01:23] 220 SmartFTP Server ready...
[20110602 15:01:53] Timeout (30s).
[20110602 15:01:53] Client closed the connection.

If I set timeout as 1000:

_connection.Host = "75.126.59.170";
_connection.Port = 21;
_connection.Username = "anonymous";
_connection.Password = "";
_connection.LogFile.File = "C:\\TEMP\\Log.log";
_connection.Timeout = 1000;


I got the following log

---Log File ---

[20110602 15:07:13] SmartFTP FTP Library 2.0.118.0
[20110602 15:07:13] Resolving host name "75.126.59.170"
[20110602 15:07:13] Connecting to 75.126.59.170 Port: 21
[20110602 15:07:13] 220 SmartFTP Server ready...
[20110602 15:08:14] 421 Connection closed, timed out.
[20110602 15:08:14] Server closed connection

Set the password to "test@test.com"

It's the same if the password changed to test@test.com


--Log File --



[20110602 15:24:01] SmartFTP FTP Library 2.0.118.0
[20110602 15:24:01] Resolving host name "75.126.59.170"
[20110602 15:24:01] Connecting to 75.126.59.170 Port: 21
[20110602 15:24:01] 220 SmartFTP Server ready...
[20110602 15:25:02] 421 Connection closed, timed out.
[20110602 15:25:02] Server closed connection

Uninstall the software firewall / antivirus product and try again.

Thanks for your reply.

Can I know why the Smart FTP client can connect to the same FTPS server?

SmartFTP is most likely not blocked by the software firewall / antivirus product.

Hi mb,

I got many assist from our IT this afternoon to work with my firewall and antivirual software. It looks like that is not a firewall issue. I pasted my code here. Can you try if you are able to connect to the SFTP. Thanks in advance.

--- SFTP.cs -----


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using sfFTPLib;

namespace SFTPTest
{
public class SFTP
{
// fields
private sfFTPLib.SSHConnection _connection = null;
private sfFTPLib.SFTPConnection _sftp = null;

// methods
public void Start()
{
// Load License Key
sfFTPLib.Global global = new sfFTPLib.Global();

string strKey = "";

// New license key format
strKey += "<?xml version=\"1.0\" ?>\r\n";
strKey += "<License>\r\n";
strKey += "<Version>2.0</Version>\r\n";
strKey += "<Id>400012345</Id>\r\n";
strKey += "<Name>name</Name>\r\n";
strKey += "<Email>user@host.com</Email>\r\n";
strKey += "<Company>company</Company>\r\n";
strKey += "<Product>SmartFTP FTP Library</Product>\r\n";
strKey += "<Features>\r\n";
strKey += "<Feature>SFTP</Feature>\r\n";
strKey += "</Features>\r\n";
strKey += "<Users>1</Users>\r\n";
strKey += "<Maintenance>2008-12-27</Maintenance>\r\n";
strKey += "<Issue>2007-12-27</Issue>\r\n";
strKey += "<Signature>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>\r\n";
strKey += "</License>\r\n";

if (global.LoadLicenseKeyData(strKey))
System.Console.WriteLine("License key verified.");
else
System.Console.WriteLine("Failed to verify license key.");

// Create our COM object through the Interop (Early Binding)
_connection = new sfFTPLib.SSHConnection();

// Late Binding
//Type t = Type.GetTypeFromProgID("sfFTPLib.SFTPConnection");
//System.Object obj = Activator.CreateInstance(t);
//_ftp = obj as ISFTPConnection;

// host settings
_connection.Host = "75.126.59.170";
_connection.Port = 21;
_connection.Username = "anonymous";
_connection.Password = "test@test.com";
_connection.LogFile.File = "C:\\TEMP\\Log.log";
_connection.Timeout = 100;
// Limit authentications
enumSSHAuthentication[] authentications = new enumSSHAuthentication[2];
authentications[0] = sfFTPLib.enumSSHAuthentication.ftpSSHAuthenticationPassword;
authentications[1] = sfFTPLib.enumSSHAuthentication.ftpSSHAuthenticationNone;
object objAuthentications = (System.Array)authentications;
//_ftp.set_Authentications(ref objAuthentications);

// This snippet shows how to read the array
System.Array arrayAuthentications = (System.Array)_connection.get_Authentications();
for (int i = 0; i < arrayAuthentications.Length; i++)
{
arrayAuthentications.GetValue(i);
}

// load private key
//sfFTPLib.KeyManager keymanager = new sfFTPLib.KeyManager();
//_ftp.PrivateKey = keymanager.LoadFile("Identity", "password");

// connect to host
System.Console.WriteLine("Connecting to \"{0}\".", _connection.Host);
sfFTPLib.enumError err = _connection.Connect();
if (err == sfFTPLib.enumError.ftpErrorSuccess)
{
SFTPTest();
_connection.Disconnect();
}
else
{
if (err == sfFTPLib.enumError.ftpErrorLicense)
System.Console.WriteLine("Please acquire a license from https://www.smartftp.com");
else
System.Console.WriteLine("Failed to connect.");
}
}

// Events
public void OnTransferProgress(System.Int32 nTransferBytesLo, System.Int32 nTransferBytesHi)
{
// Int64 nTransferBytes = nTransferBytesHi;
// nTransferBytes <<= 32;
// nTransferBytes += nTransferBytesLo;
//
// System.Console.WriteLine("Event: OnTransferProgress(\"{0}\")", nLastTransferBytes);
System.Console.WriteLine("Event: OnTransferProgress(\"{0}\")", _sftp.LastTransferBytes);
}

public void SFTPTest()
{
_sftp = _connection.CreateSFTPConnection();
if (_sftp.Connect() == sfFTPLib.enumError.ftpErrorSuccess)
{
// Setup delegates
_sftp.OnTransferProgress += new sfFTPLib._ISFTPConnectionEvents_OnTransferProgressEventHandler(OnTransferProgress);

if (_sftp.RealPath(".") == sfFTPLib.enumError.ftpErrorSuccess)
{
string strCurrentDirectory = _sftp.LastPath;
// read listing
if (_sftp.ReadDirectory(strCurrentDirectory) == sfFTPLib.enumError.ftpErrorSuccess)
{
SFTPItems items = _sftp.Items;
// Use the foreach statement to iterate through
// elements in the collection
foreach (SFTPItem objItem in items)
{
System.Console.WriteLine("Type={0}; Name={1}; Size={2}", objItem.Type, objItem.Name, objItem.Size);
}
}

// download file
// Note: No resume in this sample
int nStartPosLo = 0;
int nStartPosHi = 0;
// Use the absolute path to the source file
if (_sftp.DownloadFile("/License.txt", "License.txt", nStartPosLo, nStartPosHi, nStartPosLo, nStartPosHi) == sfFTPLib.enumError.ftpErrorSuccess)
{
System.Console.WriteLine("DownloadFile() successful.");
System.Console.WriteLine("LastTransferBytes = {0} B", _sftp.LastTransferBytes);
System.Console.WriteLine("LastTransferTime = {0} s", _sftp.LastTransferTime);
System.Console.WriteLine("LastTransferSpeed = {0} B/s", _sftp.LastTransferSpeed);
}
else
{
System.Console.WriteLine("LastStatusCode = {0}", _sftp.LastStatusCode);
System.Console.WriteLine("LastStatusMessage = {0}", _sftp.LastStatusMessage);
}
}
else
{
System.Console.WriteLine("LastStatusCode = {0}", _sftp.LastStatusCode);
System.Console.WriteLine("LastStatusMessage = {0}", _sftp.LastStatusMessage);
}
}
}
}
}




----- Program.cs ----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SFTPTest
{
class Program
{
static void Main()
{

SFTP ftps = new SFTP();
ftps.Start();
}
}
}

You are trying to connect to an FTP server using the SFTPConnection class. On ftp.smartftp.com there is no SFTP server running (only FTP and FTPS).