Please find the following code. In addition to this I forget to state that I am actually running this script on magento web store but it doesn't matter since I am getting all things okay except file transfer.
<?php
require_once('app/Mage.php');
Mage::app();
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
$array1=array();
$array2=array();
echo $destination_dir = dirname(__FILE__);
$remote_file = '/B303501/_Datenblatt.pdf';
$ftp_server = "*******";
$ftp_user = "************";
$ftp_pass = "******";
$local_file = '/E212002M';
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
foreach ($products as $product) {
array_push($array1,$product->getData("sku"));
array_push($array2,$product->getData("image"));
}
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
//echo "Connected as $ftp_user@$ftp_server";
ftp_pasv($conn_id, true);
if(!@copy('/B303501/_Datenblatt.pdf','/media/catalog/product/demo/'))
{
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
} else {
echo "File copied from remote!";
}
$i = 0;
$contents = ftp_nlist($conn_id, ".");
foreach ($contents as $cont) {
if(in_array($cont,$array1)){
echo $cont. "</br>";
$buff = ftp_rawlist($conn_id, '/'.$cont.'/');
echo "<pre>";
print_r($buff);
echo "</pre>";
$tobecopied = 'http://www.example.com/index.html';
$target = $destination_dir . '/media/catalog/product/demo/';
foreach($buff as $key){
if(!@copy('/'.$cont.'/'.$key,'/media/catalog/product/demo/'))
{
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
} else {
echo "File copied from remote!";
}
}
$i++;
}
}
} else {
echo "Couldn't connect as $ftp_user\n";
}
I am getting following error while file transfer from one server to another server.
I have both live server and I am also get logged-in successfully but can't figure out what's happening while file transfer.
The following is the error.
/var/www/clients/client348/web979/web
COPY ERROR: 2
copy(/B303501/_Datenblatt.pdf): failed to open stream: No such file or directoryB303501
Any help would be highly appreciate.
Let me know if you need any further information regarding above.
Thanks
答案 0 :(得分:2)
我认为你应该使用ftp_get而不是copy
。还要确保您的目的地存在目录层次结构,因为ftp_get
和copy
都不会为您创建缺少的目录。
答案 1 :(得分:0)
我终于解决了问题。我使用的ftp只是普通的ftp但是为了登录到另一台服务器,你需要SFTP凭证,除了以上所有都处于工作模式。
感谢您的支持