I have a script that pulls a file from an external server, and tries to save it locally (to then be processed). I'm using Varien_Io_Ftp() to facilitate this, however, upon saving the file locally, it throws the following exception, despite creating the file that is required which upsets me.
Warning: chdir(): Invalid argument (errno 22) in C:\wamp\www\xxxxx\shop\lib\Varien\Io\File.php on line 547
This line in Varien_Io_File is the only one in the vacinity that doesn't have error suppression added to it. Is this a bug, or should I be setting _iwd somewhere within my call?
Hopefully some code to explain the call below:
$importDir = Mage::getBaseDir() . DS . 'var' . DS . 'import' . DS . 'stock' . DS;
$localFile = $importDir . "StockUpdate_" . date("Y-m-d-H-i-s") . ".csv";
$file = new Varien_Io_File();
$file->mkdir($importDir);
$pickupFile = new Varien_Io_Ftp();
try {
$pickupFile->open(
array(
'host' => $host,
'user' => $username,
'password' => $password,
'timeout' => '10'
)
);
$pickupFile->cd($remoteDir);
$_fileToImportRemoteTmp = $pickupFile->read($remoteFile);
$pickupFile->close();
if (!$file->write($localFile, $_fileToImportRemoteTmp)) {
die("cannot write local file :/");
}
$file->close();
} catch (Exception $e) {
var_dump($e);
}
The exception I being thrown with this line:
if (!$file->write($localFile, $_fileToImportRemoteTmp)) {
echo $localFile
andecho $_fileToImportRemoteTmp