Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: sam/async
Octocat-spinner-32 OpenSSL.xcodeproj Change build of openssl to preserve the include directory specific to… April 09, 2014
Octocat-spinner-32 SFTPTests Start of a project file for running tests/analysis November 12, 2013
Octocat-spinner-32 libcrypto.dylib.dSYM Change build of openssl to preserve the include directory specific to… April 09, 2014
Octocat-spinner-32 libssh2 @ f1cfa55 Update libssh2 submodule to 1.4.3. November 29, 2012
Octocat-spinner-32 libssh2.dylib.dSYM Update libssh2 build to use proper headers from openssl build. April 09, 2014
Octocat-spinner-32 libssh2.xcodeproj Update libssh2 build to use proper headers from openssl build. April 09, 2014
Octocat-spinner-32 libssl.dylib.dSYM Change build of openssl to include AES CTR support. April 09, 2014
Octocat-spinner-32 openssl @ b2d951e Update openssl source and built dylibs to 1.0.1g April 09, 2014
Octocat-spinner-32 openssl-build-include Change build of openssl to preserve the include directory specific to… April 09, 2014
Octocat-spinner-32 .gitignore set a nice gitignore August 16, 2011
Octocat-spinner-32 .gitmodules Doh, change over to https for openssl too November 12, 2013
Octocat-spinner-32 CK2SFTPFileHandle.h MIT license July 16, 2013
Octocat-spinner-32 CK2SFTPFileHandle.m MIT license July 16, 2013
Octocat-spinner-32 CK2SFTPSession.h Merge branch 'master' of https://github.com/karelia/libssh2_sftp-Coco… October 30, 2013
Octocat-spinner-32 CK2SFTPSession.m Merge branch 'master' of https://github.com/karelia/libssh2_sftp-Coco… October 30, 2013
Octocat-spinner-32 CK2SSHCredential.h Merge branch 'master' of https://github.com/karelia/libssh2_sftp-Coco… October 30, 2013
Octocat-spinner-32 CK2SSHCredential.m Cast port January 22, 2014
Octocat-spinner-32 README.markdown MIT license July 16, 2013
Octocat-spinner-32 libcrypto.dylib Change build of openssl to preserve the include directory specific to… April 09, 2014
Octocat-spinner-32 libssh2-README.txt Included libssh2 ver 1.4.3 build final. December 02, 2012
Octocat-spinner-32 libssh2.dylib Update libssh2 build to use proper headers from openssl build. April 09, 2014
Octocat-spinner-32 libssl.dylib Change build of openssl to include AES CTR support. April 09, 2014
Octocat-spinner-32 openssl-README.txt Change build of openssl to preserve the include directory specific to… April 09, 2014
README.markdown

This code provides a Cocoa-friendly wrapper around libssh2's SFTP functionality, including:

  • NSFileManager-esque methods for common operations, including recursive directory creation
  • NSFileHandle subclass for convenient handling of file contents
  • Encapsulation of errors using NSError
  • Create of socket etc. needed for connecting, all from a simple NSURL
  • NSURLConnection-style authentication handling, including support for public key auth, and checking against known hosts file
  • Transcript output for your logging/diagnostic purposes

Supported Platforms

  • Mac OS X 10.5+
  • In theory, iOS, but not tested at all yet

Usage

Add these three files to your project:

  • CK2SFTPSession.*
  • libssh2.dylib

For file writing or reading, you are likely to also want these two files:

  • CK2SFTPFileHandle.*

And to authenticate using a public key, add these two files:

  • CK2SSHCredential.*

Connecting to an SFTP server

  1. Create a CK2SFTPSession instance, supplying the server's URL, and your delegate
  2. The delegate is called once connected so you can asynchronously (e.g. ask the user first) supply a credential to authenticate with. If auth fails, you have as many shots at it as the server allows
  3. Internally, an SFTP channel is opened up and the delegate is informed, ready for it to start issuing commands

If at any point the connection fails, the delegate is notified.

Multi-threading

CK2SFTPSession presently uses libssh2's blocking API, so you should generally use it on a background thread. Fortunately NSOperationQueue makes this nice and easy. We use the same threading model as libssh2, so session instances (and their file handles) are free to be used on any thread, but only one at a time.

Dependencies

Requires libssh2 1.2.8 or later. A pre-built libssh2.dylib is supplied, plus an Xcode project for building your own copy if needed.

Credits & Contributors

Written by Mike Abdullah of Karelia Software.

Thanks also to Ira Cooke for fleshing out some functionality.

Support

The code lives at https://github.com/karelia/libssh2_sftp-Cocoa-wrapper Feel free to file Issues there, but no response is guaranteed.

License

Copyright © 2011 Karelia Software

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.