i got a code that can download files from remote directory to local directory but it gives following error.
please explain meaning of the error and how to resolve it. it shows problem in second line.
my code
import paramiko, os
paramiko.util.log_to_file('/tmp/paramiko.log')
from stat import S_ISDIR
host = "ip"
port = 22
transport = paramiko.Transport((host, port))
password = "mypassword"
username = "username"
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
def sftp_walk(remotepath):
path=remotepath
files=[]
folders=[]
for f in sftp.listdir_attr(remotepath):
if S_ISDIR(f.st_mode):
folders.append(f.filename)
else:
files.append(f.filename)
if files:
yield path, files
for folder in folders:
new_path=os.path.join(remotepath,folder)
for x in sftp_walk(new_path):
yield x
for path,files in sftp_walk("." or '/remotepath/'):
for file in files:
#sftp.get(remote, local) line for dowloading.
sftp.get(os.path.join(os.path.join(path,file)), '/local path/')
error i am getting:
C:\Users\Rohan\PycharmProjects\untitled1\venv\Scripts\python.exe C:/Users/Rohan/PycharmProjects/untitled1/tyu.py
Traceback (most recent call last):
File "C:/Users/Rohan/PycharmProjects/untitled1/tyu.py", line 2, in <module>
paramiko.util.log_to_file('/tmp/paramiko.log')
File "C:\Users\Rohan\PycharmProjects\untitled1\venv\lib\site-packages\paramiko\util.py", line 252, in log_to_file
f = open(filename, "a")
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/paramiko.log'
Process finished with exit code 1