SFTP on Windows PC

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
dcahoon
Forum Newbie
Posts: 1
Joined: Sun Dec 25, 2011 5:48 pm

SFTP on Windows PC

Post by dcahoon »

I have searched everywhere for a detailed description of how to set up a php sftp client on a windows 7 machine. I found that you have to compile using visual c++ however the instructions are vague at best and all have at least one step that doesn't work. I ended up using phpseclip but would like to know if anyone has gone through this pain staking process with success. Please do not refer me to http://wiki.php.net/internals/windows/stepbystepbuild becuase a bison.exe error, b flex.exe will be a problem and c once you get past these problems this command doesn't work "configure --disable-all --enable-cli --enable-$remains". Now once you get through all of these issues you realize that there are no clear instructions on how to get the ssl_connect function to work on the windows platform. Bottom line, I am able to compile php on my windows box. I added libbssh2.lib into the deps directory. I compiled php with all of this in there. Although where the deps directory needs to reside is not real clear. Or for that matter where the libssh2.lib should be during the compilation. As you can see I have spent many hours and days trying to find the solution and each trail leads to a dead end. Any step by step instructions on how to get ssl_connect() to work on a windows pc would be greatly appreciated. Please do not refer me to a link that you have not tried yourself.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: SFTP on Windows PC

Post by Eric! »

If FTPS (FTP over SSL) is good enough, then here's a snippet out of a class showing how a connection using Curl if you have that installed.

Code: Select all

/**
 * openFTP setups up the instance for FTP connection
 *
 * @param <string> $user -- login user name
 * @param <string> $password -- password for user
 * @param <string> $host -- host location
 * @param <int> $ssl -- 0=no ssl, 1=use ssl connection
 * @param <int> $debug -- 0=no debug, 1=output debug.txt file and show it when done
 */
    public function openFTP($user, $password, $host, $ssl=0) {
        $this->curl_handle = curl_init();
        $this->user = $user;
        $this->password = $password;
        $this->host = $host;
        curl_setopt($this->curl_handle, CURLOPT_URL, "ftp://$user:$password@$host");
        if ($ssl != 0) {
            curl_setopt($this->curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($this->curl_handle, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($this->curl_handle, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
        }
        curl_setopt($this->curl_handle, CURLOPT_RETURNTRANSFER, TRUE);

        curl_exec($this->curl_handle);
        $error_no = curl_errno($this->curl_handle);
        if ($error_no != 0) {
            echo 'Problem opening connection.  CURL Error: ' . $error_no;
        }
    }
Post Reply