Skip to content

add a pake task for sftp upload #23

Description

@gggeek

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions