ftplib中没有这样的文件或目录?

2024-10-01 19:21:01 发布

您现在位置:Python中文网/ 问答频道 /正文

所以,我正在尝试为我的平板电脑和其他电脑上的文件编写一个同步程序。不幸的是,我只对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端。我做错了吗?是否有其他功能可以远程打开此文件?在


Tags: 文件inpyifaswithlineftp

热门问题