public static function test($settings) { self::_init(); // Connect to server. $server = $settings['address']; $port = '22'; // Default sFTP port. if (strstr($server, ':')) { // Handle custom sFTP port. $server_params = explode(':', $server); $server = $server_params[0]; $port = $server_params[1]; } pb_backupbuddy::status('details', 'Connecting to sFTP server...'); $sftp = new Net_SFTP($server, $port); if (!$sftp->login($settings['username'], $settings['password'])) { pb_backupbuddy::status('error', 'Connection to sFTP server FAILED.'); pb_backupbuddy::status('details', 'sFTP log (if available & enabled via full logging mode): `' . $sftp->getSFTPLog() . '`.'); return __('Unable to connect to server using host, username, and password combination provided.', 'it-l10n-backupbuddy'); } else { pb_backupbuddy::status('details', 'Success connecting to sFTP server.'); } pb_backupbuddy::status('details', 'Attempting to create path (if it does not exist)...'); if (true === $sftp->mkdir($settings['path'])) { // Try to make directory. pb_backupbuddy::status('details', 'Directory created.'); } else { pb_backupbuddy::status('details', 'Directory not created.'); } $destination_file = $settings['path'] . '/backupbuddy_test.txt'; pb_backupbuddy::status('details', 'About to put to sFTP test file `backupbuddy_test.txt` to remote location `' . $destination_file . '`.'); $send_time = -microtime(true); if (true !== $sftp->put($destination_file, 'Upload test for BackupBuddy destination. Delete me.')) { pb_backupbuddy::status('details', 'sFTP test: Failure uploading test file.'); $sftp->delete($destination_file); // Just in case it partionally made file. This has happened oddly. pb_backupbuddy::status('details', 'sFTP log (if available & enabled via full logging mode): `' . $sftp->getSFTPLog() . '`.'); return __('Failure uploading. Check path & permissions.', 'it-l10n-backupbuddy'); } else { // File uploaded. pb_backupbuddy::status('details', 'File uploaded.'); if ($settings['url'] != '') { $response = wp_remote_get(rtrim($settings['url'], '/\\') . '/backupbuddy_test.txt', array('method' => 'GET', 'timeout' => 20, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array())); if (is_wp_error($response)) { return __('Failure. Unable to connect to the provided optional URL.', 'it-l10n-backupbuddy'); } if (stristr($response['body'], 'backupbuddy') === false) { return __('Failure. The path appears valid but the URL does not correspond to it. Leave the URL blank if not using this destination for migrations.', 'it-l10n-backupbuddy'); } } pb_backupbuddy::status('details', 'sFTP test: Deleting temp test file.'); $sftp->delete($destination_file); } return true; // Success if we got this far. }
public function signup($user, $member) { // Campaign Monitor $cm_details = Config::get('services.campaignmonitor'); $campaignmonitor = new CS_REST_Subscribers($cm_details['list_id'], $cm_details['auth_details']); $result = $campaignmonitor->add(array('EmailAddress' => $user->email, 'Name' => $member->firstname . ' ' . $member->lastname, 'CustomFields' => array(), 'Resubscribe' => false)); // Boxever $keys = "?client_key=mz5gfrJyaUcG4Pc2uugPhupj3KRV5kMt&api_token=ADvnoiQ4HJsgzt5479ltfu77Z6pTCweO&"; $res = $this->curlGet('https://api.boxever.com/v1.2/customer/search.json' . $keys . "email=" . $user->email); $dobISO = new DateTime($member->dob); $nowISO = new DateTime(); $message = array('first_name' => $member->firstname, 'lastname' => $member->lastname, 'dob' => $dobISO->format(DateTime::ISO8601), 'email' => $user->email, 'phone' => $member->phone, 'address' => $member->address, 'postcode' => $member->postcode, 'state' => $member->state, 'tiff_has_flown' => $member->hasflown == 'y' ? true : false, 'tiff_flights_per_year' => $member->flightsperyear, 'tiff_member' => true, 'subscriptions' => array(array('name' => "infrequent_flyers", 'pos' => "default", 'medium' => "EMAIL", 'status' => "SUBSCRIBED", 'effectiveDate' => urlencode($nowISO->format(DateTime::ISO8601))))); foreach ($message as $key => $val) { if (gettype($val) === 'string') { $message[$key] = urlencode($val); } } // Upload to SFTP server $dstFile = "iff_data_production/{$member->id}.json"; $fileContents = json_encode($message); // set up basic connection $domain = "sftp.tiger.jba-processing.com"; try { $sftp = new Net_SFTP($domain); // Turn on logging define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX); // Attempt login if ($sftp->login('tiger_mccann', 'fsJcBsuepHMVrYrY')) { // Attempt upload $i = 0; do { $sftp->put($dstFile, $fileContents); } while ($sftp->size($dstFile) === false && ++$i < 5); } else { Log::error("SFTP Login failed"); } } catch (Exception $e) { Log::error($e); } Log::error($sftp->getSFTPLog()); // No longer sending to Boxever /* if ($res->status == 'OK' && !isset($res->customer_ref)) { // Customer doesn't exist, create new customer // // Boxever doesn't seem to return a customer_ref even if the customer exists... // So we'll attempt to add it, and if it fails, then the user already exists in our list. $message['customer_id'] = urlencode($user->email); $message = json_encode($message); $res = $this->curlGet('https://api.boxever.com/v1.2/customer/create.json' . $keys . 'message=' . $message ); } else if (isset($res->customer_ref)) { // Customer exists, update their data $message = json_encode($message); $res = $this->curlGet('https://api.boxever.com/v1.2/customer/'.$res->customer_ref[0].'/update.json' . $keys . 'message=' . $message); } else { // Initial resource request failed $boxever = 'API Failed'; } */ return $res; }
public function dataPush($date = '2014-12-14 00:00:00') { $res = array(); $dstFile = "iff_data_production/test_data.json"; $fileContents = "test content"; // set up basic connection $domain = "sftp.tiger.jba-processing.com"; try { $sftp = new Net_SFTP($domain); if ($sftp->login('tiger_mccann', 'fsJcBsuepHMVrYrY')) { $sftp->put($dstFile, $fileContents); var_dump($sftp->size($dstFile)); var_dump($sftp->size('nonexistant.json')); } } catch (Exception $e) { var_dump($e); } echo $sftp->getSFTPLog(); return; }
$sftp->chdir($sftp_dir); } echo "\n--Made sftp connection \n"; if (empty($mail_to)) { //save on server - Check permissions & security //$file = $sftp->get($filename, $filename); // //get contents of local file and use those //if (!empty($file)) $att_contents = file_get_contents($filename); //$file = $att_contents; //if (file_exists($filename)) unlink($filename); //try to remove local file echo "No e-mail address found to send the file to. The file is stored on the SFTP server ({$filepath})."; } else { //save in string $file = $sftp->get($filename); if (empty($file)) { echo $sftp->getSFTPLog(); } //else { echo "\n\n--File found: \n".$file; } } } if (empty($mail_to)) { exit('No file or e-mail address found. End of script.'); } echo "\nSending file {$filePath} via e-mail..."; //SK 20140227 Send e-mail, initialise vars. $headers = array(); $mail_subject = ''; $mail_message = array(); $mail_body = ''; $headers[] = 'From: ' . $mail_from; //ALWAYS include a FROM address