Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a pake task for sftp upload #23

Open
gggeek opened this issue Jul 24, 2012 · 3 comments
Open

add a pake task for sftp upload #23

gggeek opened this issue Jul 24, 2012 · 3 comments
Labels

Comments

@gggeek
Copy link
Collaborator

gggeek commented Jul 24, 2012

This is, afaik, not currently supported by pake, and enough of a chore to merit some pake_function of its own (either that, or have it working via pake_write_file).

From my limited web serach, it seems that using curl is better than using the ss2_sftp functions (wider installed base).

Sample code:

    $fp = fopen( $randfile, 'rb' );

    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, str_replace( 'http://', 'sftp://@', $srv ) . $remotefilename );
    if ( $user != "" ) curl_setopt( $ch, CURLOPT_USERPWD, $user );
    if ( $public_keyfile != "" ) curl_setopt( $ch, CURLOPT_SSH_PUBLIC_KEYFILE, $public_keyfile );
    if ( $private_keyfile != "" ) curl_setopt( $ch, CURLOPT_SSH_PRIVATE_KEYFILE, $private_keyfile );
    if ( $private_keypasswd != "" ) curl_setopt( $ch, CURLOPT_KEYPASSWD, $private_keypasswd );
    curl_setopt( $ch, CURLOPT_UPLOAD, 1 );
    curl_setopt( $ch, CURLOPT_INFILE, $fp );
    // set size of the file, which isn't _mandatory_ but helps libcurl to do
    // extra error checking on the upload.
    curl_setopt($ch, CURLOPT_INFILESIZE, filesize( $randfile ) );
    $ok = curl_exec( $ch );
    $errinfo = curl_error( $ch );
    curl_close( $ch );

    fclose( $fp );

    if ( !$ok )
    {
        throw new pakeException( "Couldn't write {$fullfilename} file: " . $errinfo );
    }
@indeyets
Copy link
Owner

well, there's pakeSSH::copy_to_server() which uses scp (CLI). I guess it can be "fixed" to use curl, when possible

@gggeek
Copy link
Collaborator Author

gggeek commented Jul 26, 2012

Doh, I looked around in the code for "sftp" but somehow missed that. Scp is available on windows as well (at least it is part of git and cygwin) so I guess it could do...

@indeyets
Copy link
Owner

well, I still prefer "API-powered" solutions to CLI-solutions, so this is a valid feature request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants