所以,我正在尝试为我的平板电脑和其他电脑上的文件编写一个同步程序。不幸的是,我只对python和ftplib相当熟悉。代码如下:
#DOWNLOADING
for file in rContents:
if rIsFolder(ftp, file):
rFolders.append(file)
continue
if file in contents:
print "%s already uploaded." % file
else:
try:
print ftp.pwd()
print "Downloading %s..." % file
with open(file, 'rb') as f:
ftp.retrbinary('RETR %s' % file, f.write)
print " ...done."
except:
print "Failed download of %s." % file
我特别关心这两条线:
^{pr2}$在“with open…”一行中,我得到一个错误:
Traceback (most recent call last):
File "FolderSync.py", line 145, in <module>
sync(ftp, folder, tabFolder)
File "FolderSync.py", line 67, in sync
with open(file, 'rb') as f:
IOError: [Errno 2] No such file or directory: 'u.txt'
我实际上在用ftp.nlst文件()以获取这些文件名,因此“u.txt”绝对存在,但在ftp端。我做错了吗?是否有其他功能可以远程打开此文件?在
要检索文件,您需要以写入模式(
wb
)打开文件。在替换以下行:
有:
^{pr2}$相关问题 更多 >
编程相关推荐