2014-07-18 101 views
0

我想远程获取FTP用户的目录结构。我使用[spur] [1]模块从python脚本执行此操作。我使用cron作业调用此脚本。但我得到以下无法通过cron作业运行访问EC2服务器

Traceback (most recent call last): 
    File "/mnt/voylla-staging/releases/20140717193920/voylla_scripts/snapdeal/GetOrders/getOrders.py", line 54, in <module> 
    feeds = getFeeds() 
    File "/mnt/voylla-staging/releases/20140717193920/voylla_scripts/snapdeal/GetOrders/getOrders.py", line 26, in getFeeds 
    result = shell.run(["ls", FEED_LOCATION]) 
    File "/usr/local/lib/python2.7/dist-packages/spur/ssh.py", line 73, in run 
    return self.spawn(*args, **kwargs).wait_for_result() 
    File "/usr/local/lib/python2.7/dist-packages/spur/ssh.py", line 83, in spawn 
    channel = self._get_ssh_transport().open_session() 
    File "/usr/local/lib/python2.7/dist-packages/spur/ssh.py", line 190, in _get_ssh_transport 
    raise self._connection_error(error) 
spur.ssh.ConnectionError: Error creating SSH connection 
Original error: Authentication failed. 

如果我手动运行scipt而不使用cron,它的运行完美fin! 请有人帮忙。

感谢

相关代码:

FTP_SERVER = "abc.example.com" 
FTP_USER = "root" 
FEED_LOCATION = "/home/xyz/abc" 
PROCESSED_FEED_LOCATION = "/home/xyz/def" 
PREFIX = "alpha" 

def getFeeds():                 ####returns the list of feeds in FEED_LOCATION 
    shell = spur.SshShell(hostname=FTP_SERVER, username=FTP_USER) 
    with shell: 
     result = shell.run(["ls", FEED_LOCATION]) 
     feeds = result.output.decode().split("\n") 
    return feeds 

feeds = getFeeds() 
+0

我不知道这是ssh密钥的问题。 cron作业是否与成功执行脚本时的用户一样运行?你能从cron执行一个简单的ssh命令吗,比如'ssh [email protected] ls'? – nofinator

+0

该命令运行良好。并给出预期的输出! – nish

+0

哦,我正在运行cron作为相同的用户,在两种情况下都是root – nish

回答

1

您必须指定与private_key_file选择您的私钥文件的路径。以下是documentation的示例。

# Use a private key 
spur.SshShell(
    hostname="localhost", 
    username="bob", 
    private_key_file="path/to/private.key" 
)