开发者

Is there anything similar to isfile() isdir() with ftp in Python?

开发者 https://www.devze.com 2023-01-10 19:10 出处:网络
Writing a script to retrieve logfiles from one server to NAS i need 开发者_如何学运维to determine if sth is a file or a directory.

Writing a script to retrieve logfiles from one server to NAS i need 开发者_如何学运维to determine if sth is a file or a directory. Does anybody know a simple way to determine if an element of ftp.nlst() is a file or a directory??

Thanks in advance


Consider the following code from here. It will append [F] to directories and leave the files as it is.

from ftplib import FTP
import os
ftp = FTP(self.host)
listdir = self.ftp.nlst()
for i in listdir:
    if(self.ftp.sendcmd(os.path.isdir(bool(self.ftpdir + "/" + i)))):
          self.list_box_2.Append("[F] " + i)

Check out os.path and this SO post.

0

精彩评论

暂无评论...
验证码 换一张
取 消