I am able to successfully use fopen in conjunction with the ftp protocol to open files stored on a remote server for writing and reading as coded below.
Open for Writing:
$fp = fopen("ftp://username:password@ip address/doc_uploads/" . $fileName, "wb");
$src = file_get_contents($tmpName);
fwrite($fp, $src, strlen($src));
fclose($fp);
Open for Reading:
$fp = fopen("ftp://username:password@ip address/doc_uploads/" . $fileName, "r");
$contents = file_get_contents('ftp://username:password@ip address/doc_uploads/' . $fileName);
fclose($fp);
echo $contents;
However, I’d like to use secure ftp (sftp) like I currently use when transferring files to and from this server via an ftp client like FileZilla. But I get the error “[function.fopen]: failed to open stream: No such file or directory” when I have tried the following ftps and sftp commands, with and without the port #.
$fp = fopen("ftps://username:password@ip address:port#/doc_uploads/" . $fileName, "wb");
$fp = fopen("sftp://username:password@ip address:port#/doc_uploads/" . $fileName, "wb");
Should one of these work or do I need additional configuration or something enabled in order to use these protocols? Thank you for your help.