Downloading a file from SFTP Server in Delphi [duplicate] - file

I'm writing a simple Delphi App to upload a few files to a SFTP Server. i thought i would be able to use a TIdFTP indy client but it seams as tho their is not an option for FTP Over SSH (SFTP) does anyone know of any Free / Open source Components for Delphi 2010 that would support FTP over SSH (SFTP). Due to security reasons im unable to use Active X controls so please do not respond with Active X solutions.
Thanks for the help,
Kyle

SFTP and "FTP over SSH" are two separate things, and neither involves SSL (as someone else has suggested). SFTP is a sub-protocol of SSH while "FTP over SSH" is good/bad ol' FTP tunnelled through an SSH connection with port forwarding.
Either way, what you're after is a Delphi SSH library. I was unable to find a free SSH library for Delphi and ended purchasing SecureBlackbox (http://www.eldos.com/), which is excellent by the way, although SecureBridge (http://www.devart.com) also looks pretty good.

1) SFTP is NOT FTP-over-SSH. Read the discussion here.
2) For SFTP there are no free Delphi components. You can use our SFTP client and server components for Delphi (part of SecureBlackbox product), which are supported and maintained commercial solution.

I've been using PuTTY's SCP command line utility, with catching it's standard out via the CreateProcess method.

IP*Works include SFTP component - http://www.nsoftware.com/products/component/sftp.aspx and registered user of Delphi XE a XE2 can download this from code central (ID: 28437, ID: 28012)
and for Synapse is in contrib dir demo of simple SFTP - http://synapse.ararat.cz/files/contrib/

And since October 2019, there's a DLL fork of PuTTY with Delphi units, please see
https://github.com/superflexible/TGPuttyLib
This was created to be able to achieve the highest possible transfer rates over SFTP. It's free and very easy to use (with examples).

Look at Synapse ( http://synapse.ararat.cz/doku.php/download ) suporting ssl protocole.
Exemple code: http://synapse.ararat.cz/doku.php/public:howto:tcpwithssl

Another secure connection component set is from nSoftware: http://www.nsoftware.com/ipworks/ssh/components.aspx
You get SSH Tunnel, and SFTP.
They also offer a full component set of SSL related items: http://www.nsoftware.com/ipworks/ssl/components.aspx

libssh2 (wriiten in C) supports SFTP, and we have two separate Delphi wrappers (not sure which one is better):
https://github.com/pult/libssh2_delphi
and
https://github.com/dimmaq/delphi-libssh2
SecureBridge from DevArt also support SFTP, comes with full source for the Professional Editon.

Related

Enumerate logon sessions remotely

I want to enumerate logon sessions on a remote host (citrix terminal server). What I found so far is LsaEnumerateLogonSessions() / LsaGetLogonSessionData(), but you can't call it remotely.
I read some docs about RPC, but if I understood it right, you need an extra application on the remote host that executes your functions (that's something I want to avoid).
Is there a way to implement such a thing? Maybe with the remote desktop api?
Another solution I found: http://msdn.microsoft.com/en-us/library/windows/desktop/aa370669%28v=vs.85%29.aspx
Other options include the WTS APIs: WTSEnumerateSessionsEx. If you want to be Citrix specific you can also use the XenApp PowerShell SDK.
Use Win32_LogonSession, it is possible to call WMI from a remote computer.

IDE with remote build feature that is compatible with MIT Kerberos

I'm using cluster resources from my academic provider (PDC, Sweden) that uses the MIT-Kerberos authentication protocol for the users to sign in securely.
I'm also using Netbeans to develop C and Fortran code. Netbeans has a feature that lets you build your code on a remote host while you are working on your localhost/Desktop machine. Naturally, this feature requires you to log into your remotehost.
Since Netbeans is using its own SSH client, I cannot connect to the above mentioned remotehost even if I have a valid Kerberos ticket. I have googled this issue, but couldn't find anything related to it.
Has anybody else had a similar issue?
Does anybody know of an IDE for C/Fortran that has a build on remotehost feature and is capable of using the Kerberos protocol?
Eclipse with the Photran plugin are commonly mentioned. I never used it myself, but Eclipse should also support authentication via Kerberos.
See here for more on Eclipse and SSH.

Building a centralized configuration repository

I'm trying to develop an open source application to be sort like a centralized configuration management for all Unix platform like for example (changing root password, SSH configuration, DNS settings, /etc/hosts management.... and others).
I need your feedback for what do you recommend to use as the interface for all the configuration (list of scripts will be running in the Unix Servers as a clients to read the configuration and apply it in each system "Client===>to===>Server mode"
Should I use LDAP to host the configurations and any Unix OS can talk to the LDAP to get the configuration
or Should I just save the configuration in Database (e.g. MySQL) and build a web interface to read the database and print the configuration to the client ?
or you have any other idea?
You might look into something like Chef or Puppet instead. Why re-invent the wheel?
Curl can download a file from a URL and write that file to standard output. For example, executing curl -sS http://someHost/file.cfg will download "file.cfg" from the specified web server. The "-sS" options instruct Curl to print error messages but not any any progress diagnostics. By the way, Curl supports many protocols including HTTP, FTP and LDAP, so you have flexibility in the technology you want to use to host your centralised configuration repository (CCR).
You could use curl to retrieve a configuration file from the CCR, store the result in a local file and then parse that local file.
Check out Blueprint from DevStructure. It sounds like something along the lines of what you're trying to do. Basically it reverse engineers servers and detects everything that has changed from the install state. Open-source too.
https://github.com/devstructure/blueprint (Blueprint # Github)
We are also about to launch ConfigChief which is a central configuration repository that would do what you want: central point to store configuration (with all features like versioning, audit, ACL, inheritence, etc).
Once you have that, combined with change notification, you can just run a curl as Ciaran McHale says against the CCR and get your parsed configuration file back. This would eliminate the need for writing scripts to generate config files from the outside.
If you are interested, you can signup for a beta at http://woot.configchief.com
DISCLAIMER: I guess it is obvious from the first word!

How to access SQL Server from Cocoa (Mac OS X)?

As the question says:
How to access Microsoft SQL Server 2005 from Cocoa on Mac OS X 10.5?
The database driver should be free if possible, paid solutions can be OK as well.
If you use ODBC, Actual Technologies makes a Microsoft SQL Server driver for OS X:
http://www.actualtechnologies.com/product_sqlserver.php
Some Googling suggests this question:
http://lists.apple.com/archives/Cocoa-dev/2004/Jul/msg00077.html
Which points to these two apps:
http://www.freetds.org/
http://www.macosguru.de/
Do those meet your needs? If not, can you elaborate on the question? Thanks!
FreeTDS is pretty good and fairly easy to use from Objective-C as it has a C API.
However an even easier way is to use the jTDS JDBC driver via the Java bridge. I know that Apple no longer recommends using the Java bridge but it is probably the easiest way to talk to SQL Server and if you structure you code nicely pretty much any other database on the planet.
Commenting on this because this is one of the top results on a google search for adding SQL Server connectivity to a Cocoa (MacOS) app but I don't see any current solutions listed.
FreeTDS - as Daniel suggested, is the fastest/easiest way to go but some information about how to make that happen without using the dreaded Java bridge or some kind of Python hack. Build FreeTDS with Homebrew (don't for heaven's sakes try to build it on the mac yourself), then select your project in the Xcode finder, select the "build phases" tab, then under "link binaries with libraries" link the FreeTDS library libsybdb (use either the dynamic or static one). click on the "+" sign, then choose "add other" then navigate to where the libraries are - for me the directory the libs were installed in was
/usr/local/Cellar/freetds/1.00.109/lib
then select (e.g.) libsybdb.a in that directory
You can then use the FreeTDS API or use a wrapper like this one by Martin Rybak, which is what I did (I'm using an old version of this "SQLClient" code). It works fairly straightforwardly for a SQL Server instance on AWS, and predictably slightly more complicatedly for an Azure AWS instance - I needed to hack the wrapper since the wrapper code issues a "use db" command to azure after login which Azure won't accept - for azure the database has to be set during the connection - instead I added (using the newer code from GitHub):
DBSETLDBNAME(_login, [host UTF8String]);
in the SQLClient.m file, which I added to the section:
DBSETLUSER(_login, [username UTF8String]);
DBSETLPWD(_login, _password);
DBSETLHOST(_login, [host UTF8String]);
DBSETLCHARSET(_login, [self.charset UTF8String]);
and I commented out:
if (database) {
_returnCode = dbuse(_connection, [database UTF8String]);
if (_returnCode == FAIL) {
[self connectionFailure:completion];
return;
}
}
My app is swift-based so I use a bridging header, adding to it:
#import SQLClient.h
To use the lib, something like (pseudocode since I'm not in front of my code right now):
let client = SQLClient.sharedInstance()
//I'm using the older code which uses a delegate and not notifications callback
self.client!.delegate = self
self.client!.connect("database_network_address", username: "username", password: "password", database: "database_name", completion: { (success) -> Void in
if(success) {
print ("connection has succeeded")
// now do something with the connection
self.client!.execute("select * from table_name", completion: { (data) -> Void in
//... do something with the returned array "data" per the wrapper API
})
} else {
print ("connection has NOT been success")
}
})
Let me know if you have any questions on this. This absolutely works for a Cocoa app, I use my app to upload tons of data into an Azure SQL Server instance. Good luck!

If possible how can one embed PostgreSQL?

If it's possible, I'm interested in being able to embed a PostgreSQL database, similar to sqllite. I've read that it's not possible. I'm no database expert though, so I want to hear from you.
Essentially I want PostgreSQL without all the configuration and installation. If it's possible, tell me how.
Run postgresql in a background process.
Start a separate thread in your application that would start a postgresql server in local mode either by binding it to localhost with some random free port or by using sockets (does windows support sockets?). That should be fairly easy, something like:
system("C:\Program Files\MyApplication\pgsql\postgres.exe -D C:\Documents and Settings\User\Local Settings\MyApplication\database -h 127.0.0.1 -p 12345");
and then just connect to 127.0.0.1:12345.
When your application quits, you can always send a SIGTERM to your thread and then wait a few seconds for postgresql to quit (ie join the thread).
PS: You can also use pg_ctl to control your "embedded" database, even without threads, just do a "pg_ctl start" (with appropriate options) when starting the application and "pg_ctl stop" when quitting it.
You cannot embed it, nor should you try.
For embedding you should use sqlite as you mentioned or firebird rdbms.
Unless you do a major rewrite of code, it is not possible to run Postgres "embedded". Either run it as a separate process or use something else. SQLite is an excellent choice. But there are others. MySQL has an embedded version. See it at http://mysql.com/oem/. Also several java choices, and Mac has Core Data you can write too. Hell, you can even use FoxPro. What OS you on and what services you need from the database?
You can't embed it as a in process type thing like sqlite etc, but you can easily embed it into your application setup using Inno setup at http://www.innosetup.org. Search their mailing list archive and you will find someone did most of the work for you and all you have to to is grab the zipped distro and you can easily have postgresql installed when the user installs your app. You can then use the pg_hba.conf file to restrict the server to local host only. Not a true embedded DB, but it would work.
PostgreSQL is intended to run as a stand-alone server; it's probably possible to embed it if you hack at it hard and long enough, but it would be much easier to just run it as intended in a separate process.
HSQLDB (http://hsqldb.org/) is another db which is easily embedded. Requires Java, but is an excellent and often-used choice for Java applications.
Anyone tried on Mac OS X:
http://pagesperso-orange.fr/bruno.gaufier/xhtml/prod_postgresql.xhtml
http://www.macosxguru.net/article.php?story=20041119135924825
(Of course sqlite would be my embedded db of choice as well)
Well, I know this is a very very very old post, but if anyone has nowadays this question, I would refer to:
You can use containers running Postgres. Here's a post that could be helpful, doing something along this line using R:
https://rsangole.netlify.app/post/2021/08/07/docker-based-rstudio-postgres/?utm_source=pocket_mylist
Take a look at duckdb https://duckdb.org/docs/installation/ It is relatively new and still needs to mature. But it works pretty much like an embedded database ("In-process, serverless"), with bindings for several languages (Python, R, Java, ...)

Resources