Current Path :
/
home
/
zrcdevco
/
public_html
/
zrc-email-program
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/zrcdevco/public_html/zrc-email-program/cmd_sftp_test_checks.php
<?php $host = 'sftp.cmdintegration.com'; $port = 2220; $username = 'zrcworldwide'; $password = 'MRUSWZzgmfld516^'; $remoteDir = '/zrcworldwide_insight'; $localDir = '/test_files'; if (!function_exists("ssh2_connect")) die('Function ssh2_connect not found, you cannot use ssh2 here'); if (!$connection = ssh2_connect($host, $port)) die('Unable to connect'); if (!ssh2_auth_password($connection, $username, $password)) die('Unable to authenticate.'); if (!$stream = ssh2_sftp($connection)) die('Unable to create a stream.'); if (!$dir = opendir("ssh2.sftp://{$stream}{$remoteDir}")) die('Could not open the directory'); $files = array(); while (false !== ($file = readdir($dir))) { if ($file == "." || $file == "..") continue; $files[] = $file; } $file=files[0]; //foreach ($files as $file) { echo "Copying file: $file\n"; if (!$remote = @fopen("ssh2.sftp://{$stream}/{$remoteDir}{$file}", 'r')) { echo "Unable to open remote file: $file\n"; continue; } if (!$local = @fopen($localDir . $file, 'w')) { echo "Unable to create local file: $file\n"; continue; } $read = 0; $filesize = filesize("ssh2.sftp://{$stream}/{$remoteDir}{$file}"); while ($read < $filesize && ($buffer = fread($remote, $filesize - $read))) { $read += strlen($buffer); if (fwrite($local, $buffer) === FALSE) { echo "Unable to write to local file: $file\n"; break; } } fclose($local); fclose($remote); }