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.

    http://www.php.net/manual/en/wrappers.ftp.php

    Note: FTPS is supported starting from PHP 4.3.0, if you have compiled in support for OpenSSL.

    Also:

    http://www.php.net/manual/en/function.ftp-ssl-connect.php

    ftp_ssl_connect() is only available if both the ftp module and the OpenSSL support is built statically into php, this means that on Windows this function will be undefined in the official PHP builds. To make this function available on Windows you must compile your own PHP binaries.

      Thank you very much. This is very helpful. I will mark this thread as resolved.

        Write a Reply...