命令行没有递归ftp文件的命令。我想写一个简易的,因为最近总是要传输一个文件夹,先tar再解包挺烦的。可是运行的时候报错。我看不像是我的代码的错。
难道是库函数的问题?请热心的高手帮忙看看。谢谢
import ftplib
import os
import sys
s = ftplib.FTP()
def rftp(server, user, passwd, rpath = '.'):
global s
s.connect(server)
s.login(user, passwd)
s.cwd(rpath)
ftpDir('.')
def ftpDir(path):
for afile in os.listdir(path):
if os.path.isdir(afile):
ftpDir(afile)
else:
source = open(os.path.join(path,afile))
str = "STOR " + afile
print str
s.storlines(s, source)
if __name__ == '__main__':
if len(sys.argv) < 4 or len(sys.argv) >5:
print "usage: ", sys.argv[0],"server user passwd remotepath"
rftp(sys.argv[1],sys.argv[2],sys.argv[3], sys.argv[4])
====出错信息=======================
STOR myfile.html
Traceback (most recent call last):
File "../rftp.py", line 28, in ?
rftp(sys.argv[1],sys.argv[2],sys.argv[3], sys.argv[4])
File "../rftp.py", line 12, in rftp
ftpDir('.')
File "../rftp.py", line 22, in ftpDir
s.storlines(s, source)
File "c:Python24libftplib.py", line 426, in storlines
conn = self.transfercmd(cmd)
File "c:Python24libftplib.py", line 345, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "c:Python24libftplib.py", line 327, in ntransfercmd
resp = self.sendcmd(cmd)
File "c:Python24libftplib.py", line 240, in sendcmd
self.putcmd(cmd)
File "c:Python24libftplib.py", line 175, in putcmd
self.putline(line)
File "c:Python24libftplib.py", line 168, in putline
line = line + CRLF
TypeError: unsupported operand type(s) for +: 'instance' and 'str'
|
|