{"action":"closed","issue":{"url":"https://api.github.com/repos/ktbyers/netmiko/issues/1028","repository_url":"https://api.github.com/repos/ktbyers/netmiko","labels_url":"https://api.github.com/repos/ktbyers/netmiko/issues/1028/labels{/name}","comments_url":"https://api.github.com/repos/ktbyers/netmiko/issues/1028/comments","events_url":"https://api.github.com/repos/ktbyers/netmiko/issues/1028/events","html_url":"https://github.com/ktbyers/netmiko/issues/1028","id":389251803,"node_id":"MDU6SXNzdWUzODkyNTE4MDM=","number":1028,"title":"[2.1.1] BaseFileTransfer._remote_file_size_unix() seems to incorrectly parse ls -l output","user":{"login":"Mark90","id":1482100,"node_id":"MDQ6VXNlcjE0ODIxMDA=","avatar_url":"https://avatars0.githubusercontent.com/u/1482100?v=4","gravatar_id":"","url":"https://api.github.com/users/Mark90","html_url":"https://github.com/Mark90","followers_url":"https://api.github.com/users/Mark90/followers","following_url":"https://api.github.com/users/Mark90/following{/other_user}","gists_url":"https://api.github.com/users/Mark90/gists{/gist_id}","starred_url":"https://api.github.com/users/Mark90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mark90/subscriptions","organizations_url":"https://api.github.com/users/Mark90/orgs","repos_url":"https://api.github.com/users/Mark90/repos","events_url":"https://api.github.com/users/Mark90/events{/privacy}","received_events_url":"https://api.github.com/users/Mark90/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-12-10T11:10:33Z","updated_at":"2018-12-11T05:12:13Z","closed_at":"2018-12-11T05:12:13Z","author_association":"NONE","body":"Hi,\r\n\r\nFirst, thanks for creating and maintaining a great library that is doing a lot of work for us. It's really awesome :-) \r\n\r\nI had an issue doing a file_transfer() to retrieve a remote file, using a linux connection. (version/platform details at bottom of this post)\r\n\r\n```\r\nfrom netmiko import ConnectHandler, file_transfer\r\nclient = ConnectHandler(device_type='linux')  # other args ommitted\r\nsrc = 'remote_dir/export.tar.gz'\r\ndst = 'test_export.tar.gz'\r\ndirection = 'get'\r\nres = file_transfer(client, source_file=src, dest_file=dst, direction=direction)\r\n```\r\n\r\nThis gave the following traceback;\r\n\r\n```\r\n/home/proj/test_venv/lib/python3.6/site-packages/netmiko/scp_functions.py in file_transfer(ssh_conn, source_file, dest_file, file_system, direction, disable_md5, inline_transfer, overwrite_file)\r\n     68\r\n---> 69     with TransferClass(**scp_args) as scp_transfer:\r\n     70         if scp_transfer.check_file_exists():\r\n\r\n/home/proj/test_venv/lib/python3.6/site-packages/netmiko/ssh_dispatcher.py in FileTransfer(*args, **kwargs)\r\n    208     FileTransferClass = FILE_TRANSFER_MAP[device_type]\r\n--> 209     return FileTransferClass(*args, **kwargs)\r\n\r\n/home/proj/test_venv/lib/python3.6/site-packages/netmiko/linux/linux_ssh.py in __init__(self, ssh_conn, source_file, dest_file, file_system, direction)\r\n    113                                                        file_system=file_system,\r\n--> 114                                                        direction=direction)\r\n    115\r\n\r\n/home/proj/test_venv/lib/python3.6/site-packages/netmiko/scp_handler.py in __init__(self, ssh_conn, source_file, dest_file, file_system, direction)\r\n     77             self.source_md5 = self.remote_md5(remote_file=source_file)\r\n---> 78             self.file_size = self.remote_file_size(remote_file=source_file)\r\n     79         else:\r\n\r\n/home/proj/test_venv/lib/python3.6/site-packages/netmiko/linux/linux_ssh.py in remote_file_size(self, remote_cmd, remote_file)\r\n    125         \"\"\"Get the file size of the remote file.\"\"\"\r\n--> 126         return self._remote_file_size_unix(remote_cmd=remote_cmd, remote_file=remote_file)\r\n    127\r\n\r\n/home/proj/test_venv/lib/python3.6/site-packages/netmiko/scp_handler.py in _remote_file_size_unix(self, remote_cmd, remote_file)\r\n    227         self.ssh_ctl_chan._return_cli()\r\n--> 228         return int(file_size)\r\n    229\r\n\r\nValueError: invalid literal for int() with base 10: 'file'\r\n```\r\n\r\nReplicating the remote-file-size check in https://github.com/ktbyers/netmiko/blob/master/netmiko/scp_handler.py#L221 it appears that the regex also matches error output when the file is not found:\r\n```\r\nIn [60]: remote_out\r\nOut[60]: 'ls: /var/tmp/remote_dir/export.tar.gz: No such file or directory'\r\n\r\nIn [61]: match = re.search(pattern, remote_out, flags=re.M)\r\n\r\nIn [62]: match.group(0)\r\nOut[62]: 'ls: /var/tmp/remote_dir/export.tar.gz: No such file or directory'\r\n```\r\n\r\nIn my case, the fix was simple - specify the correct directory in`file_system` parameter to file_transfer:\r\n```\r\nfrom netmiko import ConnectHandler, file_transfer\r\nclient = ConnectHandler(device_type='linux')  # other args ommitted\r\nsrc = 'remote_dir/export.tar.gz'\r\ndst = 'test_export.tar.gz'\r\ndirection = 'get'\r\nfile_system = '/home/_nonlocl'\r\nres = file_transfer(client, source_file=src, dest_file=dst, direction=direction, file_system=file_system)\r\n```\r\n\r\nThe file transfer works now, although I'm getting a \"MD5 failure between source and destination files\", but that's offtopic.\r\n\r\n\r\nA better error handling/message in _remote_file_size_unix would be helpful in my opinion.\r\nIf you take pull-requests I can try writing one up - although I might not be aware of the impact of changing this low-level function.\r\n\r\n\r\n\r\n**Machine running netmiko**\r\nOS: Debian 9 i686\r\nNetmiko: 2.1.1\r\nPython: 3.6.4\r\n\r\n**Target machine**\r\nOS: Check Point Gaia R80.10"}}
{"actor":{"display_login":"ktbyers"}}