title: Transfer large file via SFTP in PHP
body: <p>I have a large file (200 MB upwards). I need to transfer it via PHP cron job. Using <code>Phpseclib</code> gives the following error:</p>
  
  <blockquote>
    <p>Allowed memory size of 134217728 bytes exhausted (tried to allocate
    4133 bytes) in /app/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php</p>
  </blockquote>
  
  <p>Is there a way I can do this with <code>PHP cron job</code>? </p>
  
  <p>The code is simple one line where $localFile is an already existing CSV file </p>
  
  <pre><code>$sftp-&gt;put('/Import/coupons/coupons_import_test.csv', $localFile, NET_SFTP_LOCAL_FILE);
  </code></pre>
  
  <p><strong>PS</strong>. This needs to be done after <code>PHP</code> generates that file in the <code>/tmp</code> folder so timing of the transfer script has to come into play.</p>
  
  <p>[Edit]
  I do not intend on increasing the memory limit as the files later could be of higher sizes. A solution where I can transfer the file in parts (append mode) or use some shell script with PHP cron could be worthwhile</p>
  
  <p>The file size on remote server is 111.4 MB while the actual file is much larger on local.</p>
  
  <p>[Edit after the fix]
  The issue disappeared after changing to version 2.0.2 from version 1.0 
  I had to modify the code for put </p>
  
  <pre><code>$sftp-&gt;put('/Import/coupons/coupons_import.csv', $localFile, $sftp::SOURCE_LOCAL_FILE);
  </code></pre>