【发布时间】:2014-02-25 07:00:09
【问题描述】:
所以,我正在尝试为我的平板电脑和其他计算机上的文件编写一个同步程序。不幸的是,我只对 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
我特别关心这两行:
with open(file, 'rb') as f:
ftp.retrbinary('RETR %s' % file, f.write)
在 "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 方面。我做错了吗?远程打开这个文件有不同的功能吗?
【问题讨论】:
标签: python python-2.7 ftp