I see a lot of other posts on this but still unable to fix my issue. Have a simple script to ssh into a unit, search for all of the log files, then download them to a folder on local desktop. Here is the error and the last line looks like it's missing the cause. When I search for this most errors end with a file name or path of some sort. This currently does work meaning it does grab a ton of log files.
Traceback (most recent call last):
File "sshtest2.py", line 32, in <module>
ftp.get(afile, f'{filelocation}/'+filename)
File "/Users/<user>/Library/Python/3.8/lib/python/site-packages/paramiko/sftp_client.py", line 811, in get
size = self.getfo(remotepath, fl, callback, prefetch)
File "/Users/<user>/Library/Python/3.8/lib/python/site-packages/paramiko/sftp_client.py", line 783, in getfo
with self.open(remotepath, "rb") as fr:
File "/Users/<user>/Library/Python/3.8/lib/python/site-packages/paramiko/sftp_client.py", line 372, in open
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
File "/Users/<user>/Library/Python/3.8/lib/python/site-packages/paramiko/sftp_client.py", line 822, in _request
return self._read_response(num)
File "/Users/<user>/Library/Python/3.8/lib/python/site-packages/paramiko/sftp_client.py", line 874, in _read_response
self._convert_status(msg)
File "/Users/<user>/Library/Python/3.8/lib/python/site-packages/paramiko/sftp_client.py", line 905, in _convert_status
raise IOError(errno.EACCES, text)
PermissionError: [Errno 13] Permission denied
Here is the script
import paramiko
import os
# log file location
filelocation = os.path.join(os.path.join(
os.path.expanduser('~')), 'Desktop/logs')
ssh_ip = '10.0.0.40' # input("what is the ip address of the unit? ")
ssh_name = 'ubuntu' # input("what is the login name? ")
ssh_pass = 'temppwd' # input("what is the password? ")
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect(ssh_ip, username=ssh_name, password=ssh_pass)
apath = '/var/log'
apattern = '"*.log*"'
rawcommand = 'find {path} -name {pattern}'
command = rawcommand.format(path=apath, pattern=apattern)
stdin, stdout, stderr = ssh.exec_command(command)
filelist = stdout.read().decode().splitlines()
stdin.close()
print("filelist = ", filelist)
ftp = ssh.open_sftp()
if not os.path.exists(filelocation):
os.mkdir(filelocation)
for afile in filelist:
(head, filename) = os.path.split(afile)
print(filename)
ftp.get(afile, f'{filelocation}/'+filename)
ftp.close()
ssh.close()