0

我不知道我做错了什么,但是这个小 ftp 代码不会传输文件。我不断得到

文件“example.py”,第 11 行,在?ftp.storlines("STOR " + 文件,打开(文件))

ftplib.error_perm: 550 /home/helen/docs/example.txt: 不允许操作

这是代码:

import ftplib

file = '/home/helen/docs/example.txt'     
ftp = ftplib.FTP('domain', 'user', 'password')
print "File List: "
files = ftp.dir()

ftp.cwd("/upload/")

ftp.storlines("STOR " + file, open(file))

f.close()                               
s.quit()

任何帮助,将不胜感激。

4

2 回答 2

6

我认为您遇到的错误是您将整个文件路径添加到storlines()调用中的第一个参数。相反,只需指定文件名本身:

import os
ftp.storlines("STOR " + os.path.basename(file), open(file))

您可能需要考虑更改filefilepath, 因为这就是它的真正含义(另外您将不再隐藏同名的内置函数和类型)。

于 2013-05-17T20:57:20.793 回答
0

根据维基百科,550 错误字面意思是“550 未采取请求的操作。文件不可用(例如,找不到文件,无法访问)。”

http://en.wikipedia.org/wiki/List_of_FTP_server_return_codes

你确定你有正确的权限吗?

尝试这个

ftp = ftplib.FTP('domain')
ftp.login('user','pass')

我认为对象创建只是有点夸张。

于 2013-05-17T16:42:40.280 回答