title: How to SFTP upload files from PHP
body: <p>I'm having trouble using PHP to SFTP upload files to a remote server.  When I use cURL, I'm getting the error described here:</p>
  
  <p><a href="https://stackoverflow.com/questions/1766822/sftp-from-php-undefined-constant-curloptprotocols-and-curlprotosftp">SFTP from PHP - undefined constant CURLOPT_PROTOCOLS and CURLPROTO_SFTP?</a></p>
  
  <p>I also tried phpseclib as suggested in:</p>
  
  <p><a href="https://stackoverflow.com/questions/717854/sftp-from-within-php">SFTP from within PHP</a></p>
  
  <p>But when i try phpseclib, i get these errors:</p>
  
  <pre><code>Warning: require_once(Math/BigInteger.php) [function.require-once]: failed to open stream: No such file or directory in /home/john/public_html/test/Net/SSH2.php on line 53
  
  Fatal error: require_once() [function.require]: Failed opening required 'Math/BigInteger.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/john/public_html/test/Net/SSH2.php on line 53
  </code></pre>
  
  <p>I then tried using system commands in php like so, but nothing happened:</p>
  
  <pre><code>&lt;?php
  echo system('sftp user@ftp.domain.com');
  echo system('password');
  echo system('put file.csv');
  ?&gt;
  </code></pre>
  
  <p>I also tried </p>
  
  <pre><code>&lt;?php
  $connection = ssh2_connect('shell.example.com', 22);
  ssh2_auth_password($connection, 'username', 'password');
  
  ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
  ?&gt;
  </code></pre>
  
  <p>but my php server says ss2_connect is not defined.</p>
  
  <p>I tried to do the following from terminal</p>
  
  <pre><code>scp file.csv user@ftp.remote.com
  password
  </code></pre>
  
  <p>But the server does not allow scp command.  I do not have shell access to create ssh keys.</p>
  
  <p>All i can do right now is sftp from terminal and manually upload.  But I really want to automate this so a PHP website can do all this.</p>
  
  <p>There aren't many tutorials on how to SFTP upload from PHP.  Is it because it's a bad thing to do?  If so, what should I be doing?  The server I want to upload to only allows sftp connections.</p>