import ftplib
from ftplib import FTP
ftp = FTP("192.168.0.112")
ftp.login(user=username, passwd=password)
def ftp_remote_path_is_directory(ftp, remote_path):
current_path = ftp.pwd()
try:
ftp.cwd(remote_path)
except ftplib.error_perm as e:
if str(e).startwith("550"):
return False
else:
print(f"other error check error code{str(e)}")
return None
ftp.cwd(current_path)
return True
def ftp_remote_path_is_file(ftp, remote_path):
current_path = ftp.pwd()
try:
ftp.cwd(remote_path)
except ftplib.error_perm as e:
if str(e).startwith("550"):
return True
else:
print(f"other error check error code{str(e)}")
return None
ftp.cwd(current_path)
return False
python ftplib写一个判断远端路径是文件还是文件夹
于 2024-10-30 15:17:29 首次发布