In my C# project I have included ChilkatDotNet2.dll in order to connect to a SFTP server. For the moment, I have tried to implemt a simple connection method like the following:
Chilkat.Ftp2 F = null;
F = (Chilkat.Ftp2)new Chilkat.Ftp2();
F.Hostname = "sftp.domain.com";
F.Username = "username";
F.Password = "password";
F.Port = 22;
F.AuthTls = true;
if (!(F.Connect())) {
MainFrm.set_AlertMessage(F.ConnectFailReason);
}
and it always fails connecting and I always get the error 200 which means
Connected, but failed to receive greeting from FTP server.
according to Chilkat documentation.
What am I missing? I have tried to connect to a simple ftp server test (without SSL/TLS) and it connects correctly so I think I am missing something.
The credentials I was given are correct as I tried to connect to the SFTP server with Filezilla.
Thank you.
UPDATE
Chilkat.SFtp v_SFTP = null;
v_SFTP = (Chilkat.SFtp)new Chilkat.SFtp();
if (v_SFTP.Connect("sftp.domain.com", 22) {
if (v_SFTP.AuthenticatePw("username", "password")) {
IDVariant v_SUCCESS = null;
bool v_SUCCESS = v_SFTP.InitializeSftp();
}
}
else {
MainFrm.set_AlertMessage(v_SFTP.LastErrorText);
}
F = (Chilkat.Ftp2)new Chilkat.Ftp2();
Chilkat.Ftp2 is an FTP client. It supports the FTP protocol. SFTP is a completely different protocol which just happens to have a similar name.
If you want to connect to an SFTP server using Chilkat, look at Chilkat.SFtp.
Related
I am currently able to connect to the IBM MQ server based on jndi binding file with the following c# code
InitialContext ic = null;
IConnectionFactory confac = null;
IConnection conn = null;
ISession sess = null;
IMessageConsumer cons = null;
IDestination dest = null;
try
{
System.Collections.Hashtable env = new System.Collections.Hashtable();
// Set the URL or PATH where the bindings file is located
env[XMSC.IC_URL] = "file://c:/mqbindings/.bindings";
// Initialize the context
ic = new InitialContext(env);
// Lookup for the connection factory name
confac = (IConnectionFactory)ic.Lookup("myconfactoryname");
// Create connection using the details from connection factory
conn = (IConnection)confac.CreateConnection();
// Create an auto ack session
sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
// Lookup for the destination
dest = (IDestination)ic.Lookup("myqueue");
// ... rest of the code - create consumer or producer
}
catch (XMSException xmsE)
{
// Handle exception
}
However, when the SSL enabled in the IBM MQ Server, it fails to connect. Tried setting different properties (like setting XMSC.IC_PROVIDER_URL to the keystores directory/.jp12 file), but does not seem working.
Exception I got:
IBM.XMS.XMSException: 'CWSMQ0006E: An exception was received during the call to the method ConnectionFactory.CreateConnection: CompCode: 2, Reason: 2059.
I also cannot find any sample code on the official site on how this is working.
Any idea or sample code on this (not necessary in great details, at least, give me some ideas how what I need to set)?
I am Trying to Connect MY Sap B1 HANA on C# Web Based Application using DI API but my connection is giving me error. Here is Error Screenshot Failed to Connect SLD,make Sure Your SLD Server is Available and Connected. Any Relevant Help would be Appreciated.
try{
oCompany.CompanyDB = "***";
oCompany.Server = "***";
oCompany.LicenseServer = "***:30015";
oCompany.SLDServer = "***:40000"; //
oCompany.DbUserName = "****"; //
oCompany.DbPassword = "****"; //
oCompany.UserName = "****"; //
oCompany.Password = "****"; //
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
oCompany.UseTrusted = false;
int res = oCompany.Connect();
string errMsg = oCompany.GetLastErrorDescription();
int ErrNo = oCompany.GetLastErrorCode();
if (ErrNo != 0)
{
value1 = errMsg;
return errMsg;
}
else {
value1 = "Succes Connection To Sap B1 Hana";
return value1;
}
You must include the port number in the server. Usually, the port number is 30015.
you can also use below mention code.
SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
oCompany = (SAPbobsCOM.Company)Application.SBO_Application.Company.GetDICompany();
The following connection code should get you a step further:
// The actual database host
// With HANA the single-tenancy port 30015 needs to be provided together with the host (not so with MSSQL)
// When using HANA multi-tenancy the instance is prefixed and the port changed: INSTANCE#DB-HOST:30013
// OR the correct instance port needs to be provided, eg. DB-HOST:30017
sboCompany.Server = "DB-HOST:30015";
// The company database/schema name
// With MSSQL the instance is provided here like: INSTANCE\DB_NAME
sboCompany.CompanyDB = "SCHEMA";
// SLDServer is the new LicenseServer, don't forget the port with HANA
// Be aware: use either hostname or IP of SLD everywhere
sboCompany.SLDServer = "SLD-HOST:40000";
// Hell knows why the version needs to be provided for MSSQL...
sboCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
// DB credentials when using MSSQL authentication or HANA
sboCompany.UseTrusted = false;
sboCompany.DbUserName = "SYSTEM";
sboCompany.DbPassword = "password";
// SBO credentials
sboCompany.UserName = "manager";
sboCompany.Password = "password";
The next problems might be missing or wrong HANA drivers... your journey just began ;-)
I have been using windows server 2012 R2 and I have bitvise SSH for SFTP and I want to create SFTP user programmatically in my application.
What I am thinking to do is When any user signup into the application then application will create a new folder and SFTP credentials for a newly created folder.So each user can access their SFTP credentials for uploading their files in their associated folder.
I can find the solution to create FTP users dynamically but I want to create SFTP user.
Question: Is it possible to create SFTP user using c#? If it is then how?
You can create SFPT user using C# like :
var cfg = new CBssCfg726("BssCfg726.BssCfg726");
cfg.SetSite("Bitvise SSH Server");
cfg.LoadServerSettings();
cfg.settings.access.virtAccountsEx.#new.virtAccount ="Virtual Account Name";
cfg.settings.access.virtAccountsEx.#new.virtPassword.Set("Password");
cfg.settings.access.virtAccountsEx.#new.group = "Virtual Users";
//if already virtAccountsEx then first delete...
for (uint i = 0; i < cfg.settings.access.virtAccountsEx.count; i++) {
if (cfg.settings.access.virtAccountsEx.GetItem(i).virtAccount == "Virtual Account Name") {
cfg.settings.access.virtAccountsEx.Erase(i);
}
}
cfg.settings.access.virtAccountsEx.#new.fwding.srvSideC2S.ipv4Ex.#new.targetHost = "127.0.0.1";
cfg.settings.access.virtAccountsEx.#new.fwding.srvSideC2S.ipv4Ex.#new.targetPort = 80;
cfg.settings.access.virtAccountsEx.#new.fwding.srvSideC2S.ipv4Ex.#new.proxyProfile = "Default";
cfg.settings.access.virtAccountsEx.#new.loginAllowed = cfg.DefaultYesNo.yes;
cfg.settings.access.virtAccountsEx.#new.xfer.mountPointsEx.Clear();
cfg.settings.access.virtAccountsEx.#new.xfer.mountPointsEx.#new.sfsMountPath = "/";
cfg.settings.access.virtAccountsEx.#new.xfer.mountPointsEx.#new.realRootPath = "Path to folder";
cfg.settings.access.virtAccountsEx.#new.xfer.mountPointsEx.NewCommit();
cfg.settings.access.virtAccountsEx.#new.fwding.srvSideC2S.ipv4Ex.NewCommit();
cfg.settings.access.virtAccountsEx.NewCommit();
cfg.SaveServerSettings();
Our software uses a SqlConnection object to get data from SQL Server. It is running fine for many sites, but for one specific user - it cannot connect to the server. I get an exception:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server.
On this PC the executable file is located on a shared drive. If we copy the executable to a local drive (the desktop) and run it from there, the connection is successful.
Here is what I use to connect to SQL Server:
System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
builder.DataSource = SQLServerName;
builder.InitialCatalog = SQLDBName;
builder.WorkstationID = SQLServerName;
builder.PacketSize = 4096;
builder.IntegratedSecurity = true;
builder.PersistSecurityInfo = true;
builder.ApplicationName = "App";
builder.MultipleActiveResultSets = true;
using (SqlConnection myDbConn = new SqlConnection())
{
myDbConn.ConnectionString = builder.ConnectionString;
try
{
myDbConn.Open();
if (myDbConn.State != System.Data.ConnectionState.Open)
{
myDbConn.Close();
return false;
}
myDbConn.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
myDbConn.Close();
return false;
}
}
return true;
We have this problem only for a specific user on a specific PC (running Windows 7). I can't figure why moving the program from a network drive to a local drive would change its behavior. I tried adding trust assemblies full control over the shared drive with no results.
I have an issue with agsXMPP onLogin event.
when I was working on local machine everything worked just fine and when I established a connection with a server it seems that the onLogin() event is not fired up, although the connection state after I open() the connection is "Connected"
this is how I establish the connection :
Jid jid = new Jid(username, GlobalVar.server, "IM");
_connection.Server = GlobalVar.server;
_connection.Username = jid.User;
_connection.Password = psw;
_connection.Resource = jid.Resource;
_connection.Priority = 1;
_connection.Port = port;
_connection.UseSSL = useSLL;
_connection.AutoResolveConnectServer = true;
_connection.UseCompression = false;
_connection.EnableCapabilities = true;
_connection.Open();
SetDiscoInfo();
this.dadForm.DialogResult = DialogResult.OK;
MessageBox.Show(_connection.XmppConnectionState.ToString());
I tested the Openfire server with Spark IM, it seems that it works just fine so the problem is only in the configuration of my app
any ideas on how to solve this problem please
When you try to connect to an external server make sure that the property Server point on the server name and the ConnectServer on the IP address like this :
_connection.ConnectServer = "server IP adress";
_connection.Server = "server name";