[로컬]
isdir isfile
import os
print(os.path.isdir("/home/temp"))
print(os.path.isfile("/home/temp/test.txt"))
[원격]
import errno
import os
def exists_remote(sftp_client, path):
try:
sftp_client.stat(path)
except IOError as e:
if e.errno == errno.ENOENT:
return False
raise
else:
return True
stackoverflow.com/questions/4409502/directory-transfers-with-paramiko
docs.python.org/ko/3/library/errno.html
원격 경로가 파일인지 디렉토리인직 구분
import stat
def downLoadFile(sftp, remotePath, localPath):
for fileattr in sftp.listdir_attr(remotePath):
if stat.S_ISDIR(fileattr.st_mode):
sftp.get(fileattr.filename, os.path.join(localPath, fileattr.filename))
stackoverflow.com/questions/18205731/how-to-check-a-remote-path-is-a-file-or-a-directory
'시행착오 > [python]' 카테고리의 다른 글
[python] argument가 없는 lambda 람다식 (0) | 2021.05.17 |
---|---|
[python] 파이썬 daemon 데몬 만들기 (0) | 2021.05.06 |
[python] filter 함수 사용시 주의할 점 - iterator (0) | 2021.04.21 |
[python] paramiko ssh 연결되어있는 상태인지 체크법 (0) | 2021.04.15 |
[python] asyncio + multithreading: one asyncio event loop per thread (0) | 2021.04.14 |