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