1

I'm pretty new to Magento dev so forgive me if some of my terminology isn't quite right.

My module needs to download and delete XML files from a remote FTP server using the sftp protocol. I'm using the Varien_Io_Sftp class to do that.

I'm able to open the connection, change to the needed directory and retrieve the file but when I try to delete it using the Varien_Io_Sftp rm method the remote file is not deleted.

<?php
    $vcXMLOut   = "/XML/export";
    $filename   = "test.txt"
    $sftpGetFiles = new Varien_Io_Sftp();
    $sftpGetFiles->open(
        array(
            'host'  => "ftp.test.com",
            'username'  => "test",
            'password'  => "test",
            'timeout'   => '100'
        )
    );
    $sftpGetFiles->cd($vcXMLOut);
    $file = $sftpGetFiles->read($filename); //Contents of file are read successfully
    $sftpGetFiles->rm($filename);   //File remains

I've ruled out permissions problems on the file.

I'm not sure why I'm not getting any errors anywhere. Is it because this code is being run in a cron schedule? The database says the scheduled jobs were successful. Nothing that I can find in any logs.

Any idea what I'm doing wrong here? Anyone have any ideas how I could better debug this code?

1

After some poking around it looks like that while the read method accepts a filename relative to the current directory, the rm method needs the path included. The following code works for me.

<?php
    $vcXMLOut   = "/XML/export";
    $filename   = "test.txt"
    $sftpGetFiles = new Varien_Io_Sftp();
    $sftpGetFiles->open(
        array(
            'host'  => "ftp.test.com",
            'username'  => "test",
            'password'  => "test",
            'timeout'   => '100'
        )
    );
    $sftpGetFiles->cd($vcXMLOut);
    $file = $sftpGetFiles->read($filename); //Contents of file are read successfully
    $sftpGetFiles->rm($sftpGetFiles->pwd().$filename);   //File is successfully deleted
  • I'm still interested in learning ways I could have better debugged this and I'm positive that someone could give a more complete answer than I could. Please feel free to add other answers! – Dave Franks Mar 11 '16 at 17:58

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.