Php 故障排除varien_Io_sftp()通过sftp从远程主机传输
在底部更新强> 我们已经为Magento编写了一个脚本,它可以连接到第三方远程SFTP主机并获取文件以在本地进行处理 当我们运行脚本并从远程测试服务器拉取时,一切都正常运行。文件被复制到本地导入目录,导入将按其应有的方式运行。订单状态更改为“完成” 当我们尝试运行相同的测试,从远程SFTP主机连接并拉取文件时,文件不会被复制,进程将在此停止 来自远程SFTP主机的打印语句显示连接成功、目录更改和文件列表Php 故障排除varien_Io_sftp()通过sftp从远程主机传输,php,magento,sftp,Php,Magento,Sftp,在底部更新 我们已经为Magento编写了一个脚本,它可以连接到第三方远程SFTP主机并获取文件以在本地进行处理 当我们运行脚本并从远程测试服务器拉取时,一切都正常运行。文件被复制到本地导入目录,导入将按其应有的方式运行。订单状态更改为“完成” 当我们尝试运行相同的测试,从远程SFTP主机连接并拉取文件时,文件不会被复制,进程将在此停止 来自远程SFTP主机的打印语句显示连接成功、目录更改和文件列表 <?php class My_Import_Model_myfileimport {
<?php
class My_Import_Model_myfileimport
{
public function __construct(){}
/**
* Public method that is called to execute the file import.
*/
public function run()
{
if (Mage::getStoreConfig('file_processing/ifile_status/enabled') == 1):
//Instantiate the FTP object
$sftpDumpFile = new Varien_Io_Sftp();
//Try connecting to the ftp source via sftp
try {
$sftpDumpFile->open(
array(
'host' => Mage::getStoreConfig('file_processing/ifile_ftp/host'),
'username' => Mage::getStoreConfig('file_processing/ifile_ftp/username'),
'password' => Mage::getStoreConfig('file_processing/ifile_ftp/password'),
'timeout' => Mage::getStoreConfig('file_processing/ifile_ftp/timeout')
)
);
//change directory.
$sftpDumpFile->cd(Mage::getStoreConfig('file_processing/ifile_ftp/file_location'));
//get the content of the specified directory
$directory_content_array = $sftpDumpFile->ls();
print "\n Test directory: \n";
print $sftpDumpFile->pwd();
print "\n";
print "\n test remote ls array: \n";
print var_dump($directory_content_array);
print "\n";
//Get the content of the specified directory and then loop through to grab the documents to transfer locally and then remove them from the ftp server.
foreach($directory_content_array as $item):
print "\n For Each: \n";
print $item['text'];
print "\n";
if (($item['text'] != '.') && ($item['text'] != '..') && (!strstr($item['text'],'processed')) && (strtolower($item['text']) != '.ds_store')):
if($item['text']):
if (strstr($item['text'],'_FILE_')):
try{
$sftpDumpFile->read($item['text'],Mage::getBaseDir('var').'/import/'.$item['text']);
die(); //Check to see if file is copied locally
print "\n Reading: \n";
print $sftpDumpFile->read($item['text'],Mage::getBaseDir('var').'/import/'.$item['text']);
print "\n";
$sftpDumpFile->rm($item['id']);
endif;
endif;
endif;
endforeach;
} catch(Exception $e) {
Mage::log('There was a processing error when transferring files from the FTP server.');
Mage::logException($e);
}
但是,我不确定问题出在哪里,我从远程SFTP主机得到的帮助很少
在过去,我们发现这些问题通常是权限或被动FTP问题。由于我们正在连接SFTP,它建立了一个单一的直接TCP连接,我认为可以肯定地说,这可能不是一个被动FTP问题
远程SFTP帐户文件夹权限为700,文件权限为600
我在测试服务器上复制了这些权限。同样,脚本按预期运行
有什么想法吗
更新
所以它看起来像是更换了我的模具();与:
给了我一些非常有用的信息:
[channel_open_failure_reasons] => Array
(
[1] => NET_SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED
)
[terminal_modes] => Array
(
[0] => NET_SSH2_TTY_OP_END
)
[sftp_errors] => Array
(
[0] => NET_SFTP_STATUS_FAILURE: The message [/import/filename] is not extractable!
)
)
通过谷歌搜索错误“NET\u SSH2\u OPEN\u administrative\u probited”,可以看出此脚本可能需要远程主机启用
AllowTCPForwarding yes
我非常怀疑他们是否愿意这样做。有没有办法绕过这种需要
更新2
即使传输成功,也会出现以下错误:
NET_SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED
似乎返回的唯一错误是:
NET_SFTP_STATUS_FAILURE: The message [/import/filename] is not extractable!
NET_SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED
NET_SFTP_STATUS_FAILURE: The message [/import/filename] is not extractable!