Python FTP不会传输

Hel*_*ely 0 python ftp

我不知道我做错了什么,但这个小的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()
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

mar*_*eau 6

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

import os
ftp.storlines("STOR " + os.path.basename(file), open(file))
Run Code Online (Sandbox Code Playgroud)

您可能需要考虑更改filefilepath,因为它实际上是这样(加上您将不再隐藏内置函数和同名类型).