3

Hi I want to upload tar gz format file to server using varien sftp

Please give suggestion

7

To upload file on server with varian sftp use try below mentioned code i have tested and it working.

Replace some.server.com with your host Replace username with your server sftp user name Replace password with sftp password.

$localfilename = 'filename.tar.gz'; /* Local filelocation if you are using windows and file is in d: then your filename should 'd:\filename.tar.gz' and if you are using linux your file and your file is in /home/yourfolder then your local file name should '/home/yourfolder/filename.tar.gz' */
$remotefilename = '/filename.tar.gz'; /* Remote filelocation example you want upload file in /home/wesite1/public_html then your remote filename should  '/home/wesite1/public_html/filename.tar.gz' */
$sftp = new Varien_Io_Sftp();
try{
    $sftp->open(
        array(
            'host'      => 'some.server.com',
            'username'  => 'username',
            'password'  => 'password',
            'timeout'   => '10'
        )
    );
    $sftp->write($remotefilename,$localfilename);
}catch(Exception $e){
    echo $e->getMessage();
}
| improve this answer | |
  • Yes, its working for me Thanks oa lot Aman.... – user40262 May 26 '16 at 12:59
  • You welcome always it would be great if you accept answer and vote it. Thanks – Aman Alam May 26 '16 at 13:01
  • @user40262 if the answer is sufficient please mark as accepted – philwinkle May 26 '16 at 13:14
  • 1
    @AmanAlam it doesn't work for me. Using $localfilename and $remotefilename of your example, in my server it creates a file named filename.tar.gz ($remotefilename) containing just a string: filename.tar.gz ($localfilename). Checking Varien lib, the method write() in Sftp.php file, it calls the put method of phpseclib/Net/SFTP.php library without passing the $mode parameter which as default has STRING mode: function put($remote_file, $data, $mode = NET_SFTP_STRING) How can I solve without touching the core? – WaPoNe Nov 12 '18 at 17:10
  • 1
    @WaPoNe I think it's a bug. In my case $sftp->write($remotefilename,file_get_contents($localfilename)) works fine. – SeStro Nov 14 '18 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.