【发布时间】:2016-04-26 13:18:20
【问题描述】:
我正在用 getopt 编写一个 ftp 上传器。如果使用fullname = 'file.jpg' 一切正常,但如果fullname = newfiles 没有打开并返回错误通知:
AttributeError: 'list' 对象没有属性 'rfind'
也许我的应用没有发送文件的权限?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import getopt
import ftplib
import os
def usage():
print "Home"
#if __name__ == "__main__":
try:
opts, args = getopt.getopt(sys.argv[1:], "uhc", ["upload=", "help", "connect"])
except getopt.GetoptError:
usage()
sys.exit(2)
if opts == []:
usage()
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
elif opt in ("-u", "--upload"):
newfile = args
if not file:
print "Nie wybrano pliku!"
else:
print "Wybrany plik",newfile
ftp = ftplib.FTP()
ftp.connect('host')
ftp.login('user', 'pass')
ftp.cwd('./')
print "Wybieram:", ftp.pwd()
print "Wgrywam"
fullname = newfile
name = os.path.split(fullname)[1]
f = open(fullname, "rb")
ftp.storbinary('STOR ' + name, f)
f.close()
print "OK"
print "Files:"
print ftp.retrlines('LIST')
ftp.quit()
elif opt in ("-c", "--connect"):
print "a"
【问题讨论】:
标签: python bash file-upload ftp getopt