We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ftpget on python2
```
          File "/home/cowrie/cowrie/src/cowrie/commands/ftpget.py", line 200, in ftp_download
            ftp = FTP(source_address=out_addr)
          File "/home/cowrie/cowrie/src/cowrie/commands/ftpget.py", line 24, in __init__
            super(FTP, self).__init__(*args, **kwargs)
        exceptions.TypeError: super() argument 1 must be type, not classobj
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cowrie/commands/ftpget.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Author: Claud Xiao
3 
4 from __future__ import absolute_import, division
5 
6 import ftplib
7 import getopt
8 import os
9 import socket
10 
11 from twisted.python import log
12 
13 from cowrie.core.artifact import Artifact
14 from cowrie.core.config import CONFIG
15 from cowrie.shell.command import HoneyPotCommand
16 
17 commands = {}
18 
19 
20 class FTP(ftplib.FTP):
21 
22     def __init__(self, *args, **kwargs):
23         self.source_address = kwargs.pop("source_address", None)
24         super(FTP, self).__init__(*args, **kwargs)
25 
26     def connect(self, host='', port=0, timeout=-999, source_address=None):
27         if host != '':
28             self.host = host
29         if port > 0:
30             self.port = port
31         if timeout != -999:
32             self.timeout = timeout
33         if source_address is not None:
34             self.source_address = source_address
35         self.sock = socket.create_connection((self.host, self.port), self.timeout,
36                                              self.source_address)
37         self.af = self.sock.family
38         self.file = self.sock.makefile('rb')
39         self.welcome = self.getresp()
40         return self.welcome
41 
42     def ntransfercmd(self, cmd, rest=None):
43         size = None
44         if self.passiveserver:
45             host, port = self.makepasv()
46             conn = socket.create_connection((host, port), self.timeout,
47                                             self.source_address)
48             try:
49                 if rest is not None:
50                     self.sendcmd("REST %s" % rest)
51                 resp = self.sendcmd(cmd)
52                 if resp[0] == '2':
53                     resp = self.getresp()
54                 if resp[0] != '1':
55                     raise ftplib.error_reply(resp)
56             except Exception:
57                 conn.close()
58                 raise
59         else:
60             sock = self.makeport()
61             try:
62                 if rest is not None:
63                     self.sendcmd("REST %s" % rest)
64                 resp = self.sendcmd(cmd)
65                 if resp[0] == '2':
66                     resp = self.getresp()
67                 if resp[0] != '1':
68                     raise ftplib.error_reply(resp)
69                 conn, sockaddr = sock.accept()
70                 if self.timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
71                     conn.settimeout(self.timeout)
72             finally:
73                 sock.close()
74         if resp[:3] == '150':
75             size = ftplib.parse150(resp)
76         return conn, size
77 
78 
79 class command_ftpget(HoneyPotCommand):
80 
81     def help(self):
82         self.write("""BusyBox v1.20.2 (2016-06-22 15:12:53 EDT) multi-call binary.
83 
84 Usage: ftpget [OPTIONS] HOST [LOCAL_FILE] REMOTE_FILE
85 
86 Download a file via FTP
87 
88     -c Continue previous transfer
89     -v Verbose
90     -u USER     Username
91     -p PASS     Password
92     -P NUM      Port\n\n""")
93 
94     def start(self):
95         try:
96             optlist, args = getopt.getopt(self.args, 'cvu:p:P:')
97         except getopt.GetoptError:
98             self.help()
99             self.exit()
100             return
101 
102         if len(args) < 2:
103             self.help()
104             self.exit()
105             return
106 
107         self.verbose = False
108         self.username = ''
109         self.password = ''
110         self.port = 21
111         self.host = ''
112         self.local_file = ''
113         self.remote_path = ''
114 
115         for opt in optlist:
116             if opt[0] == '-v':
117                 self.verbose = True
118             elif opt[0] == '-u':
119                 self.username = opt[1]
120             elif opt[0] == '-p':
121                 self.password = opt[1]
122             elif opt[0] == '-P':
123                 try:
124                     self.port = int(opt[1])
125                 except ValueError:
126                     pass
127 
128         if len(args) == 2:
129             self.host, self.remote_path = args
130         elif len(args) >= 3:
131             self.host, self.local_file, self.remote_path = args[:3]
132 
133         self.remote_dir = os.path.dirname(self.remote_path)
134         self.remote_file = os.path.basename(self.remote_path)
135         if not self.local_file:
136             self.local_file = self.remote_file
137 
138         fakeoutfile = self.fs.resolve_path(self.local_file, self.protocol.cwd)
139         path = os.path.dirname(fakeoutfile)
140         if not path or not self.fs.exists(path) or not self.fs.isdir(path):
141             self.write('ftpget: can\'t open \'%s\': No such file or directory' % self.local_file)
142             self.exit()
143             return
144 
145         self.download_path = CONFIG.get('honeypot', 'download_path')
146 
147         self.url_log = 'ftp://'
148         if self.username:
149             self.url_log = '{}{}'.format(self.url_log, self.username)
150             if self.password:
151                 self.url_log = '{}:{}'.format(self.url_log, self.password)
152             self.url_log = '{}@'.format(self.url_log)
153         self.url_log = '{}{}'.format(self.url_log, self.host)
154         if self.port != 21:
155             self.url_log = '{}:{}'.format(self.url_log, self.port)
156         self.url_log = '{}/{}'.format(self.url_log, self.remote_path)
157 
158         self.artifactFile = Artifact(self.local_file)
159 
160         result = self.ftp_download()
161 
162         self.artifactFile.close()
163 
164         if not result:
165             # log to cowrie.log
166             log.msg(format='Attempt to download file(s) from URL (%(url)s) failed',
167                     url=self.url_log)
168 
169             self.protocol.logDispatch(eventid='cowrie.session.file_download.failed',
170                                       format='Attempt to download file(s) from URL (%(url)s) failed',
171                                       url=self.url_log)
172             self.exit()
173             return
174 
175         # log to cowrie.log
176         log.msg(format='Downloaded URL (%(url)s) with SHA-256 %(shasum)s to %(outfile)s',
177                 url=self.url_log,
178                 outfile=self.artifactFile.shasumFilename,
179                 shasum=self.artifactFile.shasum)
180 
181         self.protocol.logDispatch(eventid='cowrie.session.file_download',
182                                   format='Downloaded URL (%(url)s) with SHA-256 %(shasum)s to %(outfile)s',
183                                   url=self.url_log,
184                                   outfile=self.artifactFile.shasumFilename,
185                                   shasum=self.artifactFile.shasum,
186                                   destfile=self.local_file)
187 
188         # Update the honeyfs to point to downloaded file
189         self.fs.mkfile(fakeoutfile, 0, 0, os.path.getsize(self.artifactFile.shasumFilename), 33188)
190         self.fs.update_realfile(self.fs.getfile(fakeoutfile), self.artifactFile.shasumFilename)
191         self.fs.chown(fakeoutfile, self.protocol.user.uid, self.protocol.user.gid)
192 
193         self.exit()
194 
195     def ftp_download(self):
196         out_addr = ('', 0)
197         if CONFIG.has_option('honeypot', 'out_addr'):
198             out_addr = (CONFIG.get('honeypot', 'out_addr'), 0)
199 
200         ftp = FTP(source_address=out_addr)
201 
202         # connect
203         if self.verbose:
204             self.write('Connecting to %s\n' % self.host)  # TODO: add its IP address after the host
205 
206         try:
207             ftp.connect(host=self.host, port=self.port, timeout=30)
208         except Exception as e:
209             log.msg('FTP connect failed: host=%s, port=%s, err=%s' % (self.host, self.port, str(e)))
210             self.write('ftpget: can\'t connect to remote host: Connection refused\n')
211             return False
212 
213         # login
214         if self.verbose:
215             self.write('ftpget: cmd (null) (null)\n')
216             if self.username:
217                 self.write('ftpget: cmd USER %s\n' % self.username)
218             else:
219                 self.write('ftpget: cmd USER anonymous\n')
220             if self.password:
221                 self.write('ftpget: cmd PASS %s\n' % self.password)
222             else:
223                 self.write('ftpget: cmd PASS busybox@\n')
224 
225         try:
226             ftp.login(user=self.username, passwd=self.password)
227         except Exception as e:
228             log.msg('FTP login failed: user=%s, passwd=%s, err=%s' % (self.username, self.password, str(e)))
229             self.write('ftpget: unexpected server response to USER: %s\n' % str(e))
230             try:
231                 ftp.quit()
232             except socket.timeout:
233                 pass
234             return False
235 
236         # download
237         if self.verbose:
238             self.write('ftpget: cmd TYPE I (null)\n')
239             self.write('ftpget: cmd PASV (null)\n')
240             self.write('ftpget: cmd SIZE %s\n' % self.remote_path)
241             self.write('ftpget: cmd RETR %s\n' % self.remote_path)
242 
243         try:
244             ftp.cwd(self.remote_dir)
245             ftp.retrbinary('RETR %s' % self.remote_file, self.artifactFile.write)
246         except Exception as e:
247             log.msg('FTP retrieval failed: %s' % str(e))
248             self.write('ftpget: unexpected server response to USER: %s\n' % str(e))
249             try:
250                 ftp.quit()
251             except socket.timeout:
252                 pass
253             return False
254 
255         # quit
256         if self.verbose:
257             self.write('ftpget: cmd (null) (null)\n')
258             self.write('ftpget: cmd QUIT (null)\n')
259 
260         try:
261             ftp.quit()
262         except socket.timeout:
263             pass
264 
265         return True
266 
267 
268 commands['/usr/bin/ftpget'] = command_ftpget
269 commands['ftpget'] = command_ftpget
270
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cowrie/commands/ftpget.py b/src/cowrie/commands/ftpget.py
--- a/src/cowrie/commands/ftpget.py
+++ b/src/cowrie/commands/ftpget.py
@@ -21,7 +21,7 @@
 
     def __init__(self, *args, **kwargs):
         self.source_address = kwargs.pop("source_address", None)
-        super(FTP, self).__init__(*args, **kwargs)
+        ftplib.FTP.__init__(self, *args, **kwargs)
 
     def connect(self, host='', port=0, timeout=-999, source_address=None):
         if host != '':

{"golden_diff": "diff --git a/src/cowrie/commands/ftpget.py b/src/cowrie/commands/ftpget.py\n--- a/src/cowrie/commands/ftpget.py\n+++ b/src/cowrie/commands/ftpget.py\n@@ -21,7 +21,7 @@\n \n     def __init__(self, *args, **kwargs):\n         self.source_address = kwargs.pop(\"source_address\", None)\n-        super(FTP, self).__init__(*args, **kwargs)\n+        ftplib.FTP.__init__(self, *args, **kwargs)\n \n     def connect(self, host='', port=0, timeout=-999, source_address=None):\n         if host != '':\n", "issue": "ftpget on python2\n```\r\n          File \"/home/cowrie/cowrie/src/cowrie/commands/ftpget.py\", line 200, in ftp_download\r\n            ftp = FTP(source_address=out_addr)\r\n          File \"/home/cowrie/cowrie/src/cowrie/commands/ftpget.py\", line 24, in __init__\r\n            super(FTP, self).__init__(*args, **kwargs)\r\n        exceptions.TypeError: super() argument 1 must be type, not classobj\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Author: Claud Xiao\n\nfrom __future__ import absolute_import, division\n\nimport ftplib\nimport getopt\nimport os\nimport socket\n\nfrom twisted.python import log\n\nfrom cowrie.core.artifact import Artifact\nfrom cowrie.core.config import CONFIG\nfrom cowrie.shell.command import HoneyPotCommand\n\ncommands = {}\n\n\nclass FTP(ftplib.FTP):\n\n    def __init__(self, *args, **kwargs):\n        self.source_address = kwargs.pop(\"source_address\", None)\n        super(FTP, self).__init__(*args, **kwargs)\n\n    def connect(self, host='', port=0, timeout=-999, source_address=None):\n        if host != '':\n            self.host = host\n        if port > 0:\n            self.port = port\n        if timeout != -999:\n            self.timeout = timeout\n        if source_address is not None:\n            self.source_address = source_address\n        self.sock = socket.create_connection((self.host, self.port), self.timeout,\n                                             self.source_address)\n        self.af = self.sock.family\n        self.file = self.sock.makefile('rb')\n        self.welcome = self.getresp()\n        return self.welcome\n\n    def ntransfercmd(self, cmd, rest=None):\n        size = None\n        if self.passiveserver:\n            host, port = self.makepasv()\n            conn = socket.create_connection((host, port), self.timeout,\n                                            self.source_address)\n            try:\n                if rest is not None:\n                    self.sendcmd(\"REST %s\" % rest)\n                resp = self.sendcmd(cmd)\n                if resp[0] == '2':\n                    resp = self.getresp()\n                if resp[0] != '1':\n                    raise ftplib.error_reply(resp)\n            except Exception:\n                conn.close()\n                raise\n        else:\n            sock = self.makeport()\n            try:\n                if rest is not None:\n                    self.sendcmd(\"REST %s\" % rest)\n                resp = self.sendcmd(cmd)\n                if resp[0] == '2':\n                    resp = self.getresp()\n                if resp[0] != '1':\n                    raise ftplib.error_reply(resp)\n                conn, sockaddr = sock.accept()\n                if self.timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:\n                    conn.settimeout(self.timeout)\n            finally:\n                sock.close()\n        if resp[:3] == '150':\n            size = ftplib.parse150(resp)\n        return conn, size\n\n\nclass command_ftpget(HoneyPotCommand):\n\n    def help(self):\n        self.write(\"\"\"BusyBox v1.20.2 (2016-06-22 15:12:53 EDT) multi-call binary.\n\nUsage: ftpget [OPTIONS] HOST [LOCAL_FILE] REMOTE_FILE\n\nDownload a file via FTP\n\n    -c Continue previous transfer\n    -v Verbose\n    -u USER     Username\n    -p PASS     Password\n    -P NUM      Port\\n\\n\"\"\")\n\n    def start(self):\n        try:\n            optlist, args = getopt.getopt(self.args, 'cvu:p:P:')\n        except getopt.GetoptError:\n            self.help()\n            self.exit()\n            return\n\n        if len(args) < 2:\n            self.help()\n            self.exit()\n            return\n\n        self.verbose = False\n        self.username = ''\n        self.password = ''\n        self.port = 21\n        self.host = ''\n        self.local_file = ''\n        self.remote_path = ''\n\n        for opt in optlist:\n            if opt[0] == '-v':\n                self.verbose = True\n            elif opt[0] == '-u':\n                self.username = opt[1]\n            elif opt[0] == '-p':\n                self.password = opt[1]\n            elif opt[0] == '-P':\n                try:\n                    self.port = int(opt[1])\n                except ValueError:\n                    pass\n\n        if len(args) == 2:\n            self.host, self.remote_path = args\n        elif len(args) >= 3:\n            self.host, self.local_file, self.remote_path = args[:3]\n\n        self.remote_dir = os.path.dirname(self.remote_path)\n        self.remote_file = os.path.basename(self.remote_path)\n        if not self.local_file:\n            self.local_file = self.remote_file\n\n        fakeoutfile = self.fs.resolve_path(self.local_file, self.protocol.cwd)\n        path = os.path.dirname(fakeoutfile)\n        if not path or not self.fs.exists(path) or not self.fs.isdir(path):\n            self.write('ftpget: can\\'t open \\'%s\\': No such file or directory' % self.local_file)\n            self.exit()\n            return\n\n        self.download_path = CONFIG.get('honeypot', 'download_path')\n\n        self.url_log = 'ftp://'\n        if self.username:\n            self.url_log = '{}{}'.format(self.url_log, self.username)\n            if self.password:\n                self.url_log = '{}:{}'.format(self.url_log, self.password)\n            self.url_log = '{}@'.format(self.url_log)\n        self.url_log = '{}{}'.format(self.url_log, self.host)\n        if self.port != 21:\n            self.url_log = '{}:{}'.format(self.url_log, self.port)\n        self.url_log = '{}/{}'.format(self.url_log, self.remote_path)\n\n        self.artifactFile = Artifact(self.local_file)\n\n        result = self.ftp_download()\n\n        self.artifactFile.close()\n\n        if not result:\n            # log to cowrie.log\n            log.msg(format='Attempt to download file(s) from URL (%(url)s) failed',\n                    url=self.url_log)\n\n            self.protocol.logDispatch(eventid='cowrie.session.file_download.failed',\n                                      format='Attempt to download file(s) from URL (%(url)s) failed',\n                                      url=self.url_log)\n            self.exit()\n            return\n\n        # log to cowrie.log\n        log.msg(format='Downloaded URL (%(url)s) with SHA-256 %(shasum)s to %(outfile)s',\n                url=self.url_log,\n                outfile=self.artifactFile.shasumFilename,\n                shasum=self.artifactFile.shasum)\n\n        self.protocol.logDispatch(eventid='cowrie.session.file_download',\n                                  format='Downloaded URL (%(url)s) with SHA-256 %(shasum)s to %(outfile)s',\n                                  url=self.url_log,\n                                  outfile=self.artifactFile.shasumFilename,\n                                  shasum=self.artifactFile.shasum,\n                                  destfile=self.local_file)\n\n        # Update the honeyfs to point to downloaded file\n        self.fs.mkfile(fakeoutfile, 0, 0, os.path.getsize(self.artifactFile.shasumFilename), 33188)\n        self.fs.update_realfile(self.fs.getfile(fakeoutfile), self.artifactFile.shasumFilename)\n        self.fs.chown(fakeoutfile, self.protocol.user.uid, self.protocol.user.gid)\n\n        self.exit()\n\n    def ftp_download(self):\n        out_addr = ('', 0)\n        if CONFIG.has_option('honeypot', 'out_addr'):\n            out_addr = (CONFIG.get('honeypot', 'out_addr'), 0)\n\n        ftp = FTP(source_address=out_addr)\n\n        # connect\n        if self.verbose:\n            self.write('Connecting to %s\\n' % self.host)  # TODO: add its IP address after the host\n\n        try:\n            ftp.connect(host=self.host, port=self.port, timeout=30)\n        except Exception as e:\n            log.msg('FTP connect failed: host=%s, port=%s, err=%s' % (self.host, self.port, str(e)))\n            self.write('ftpget: can\\'t connect to remote host: Connection refused\\n')\n            return False\n\n        # login\n        if self.verbose:\n            self.write('ftpget: cmd (null) (null)\\n')\n            if self.username:\n                self.write('ftpget: cmd USER %s\\n' % self.username)\n            else:\n                self.write('ftpget: cmd USER anonymous\\n')\n            if self.password:\n                self.write('ftpget: cmd PASS %s\\n' % self.password)\n            else:\n                self.write('ftpget: cmd PASS busybox@\\n')\n\n        try:\n            ftp.login(user=self.username, passwd=self.password)\n        except Exception as e:\n            log.msg('FTP login failed: user=%s, passwd=%s, err=%s' % (self.username, self.password, str(e)))\n            self.write('ftpget: unexpected server response to USER: %s\\n' % str(e))\n            try:\n                ftp.quit()\n            except socket.timeout:\n                pass\n            return False\n\n        # download\n        if self.verbose:\n            self.write('ftpget: cmd TYPE I (null)\\n')\n            self.write('ftpget: cmd PASV (null)\\n')\n            self.write('ftpget: cmd SIZE %s\\n' % self.remote_path)\n            self.write('ftpget: cmd RETR %s\\n' % self.remote_path)\n\n        try:\n            ftp.cwd(self.remote_dir)\n            ftp.retrbinary('RETR %s' % self.remote_file, self.artifactFile.write)\n        except Exception as e:\n            log.msg('FTP retrieval failed: %s' % str(e))\n            self.write('ftpget: unexpected server response to USER: %s\\n' % str(e))\n            try:\n                ftp.quit()\n            except socket.timeout:\n                pass\n            return False\n\n        # quit\n        if self.verbose:\n            self.write('ftpget: cmd (null) (null)\\n')\n            self.write('ftpget: cmd QUIT (null)\\n')\n\n        try:\n            ftp.quit()\n        except socket.timeout:\n            pass\n\n        return True\n\n\ncommands['/usr/bin/ftpget'] = command_ftpget\ncommands['ftpget'] = command_ftpget\n", "path": "src/cowrie/commands/ftpget.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Author: Claud Xiao\n\nfrom __future__ import absolute_import, division\n\nimport ftplib\nimport getopt\nimport os\nimport socket\n\nfrom twisted.python import log\n\nfrom cowrie.core.artifact import Artifact\nfrom cowrie.core.config import CONFIG\nfrom cowrie.shell.command import HoneyPotCommand\n\ncommands = {}\n\n\nclass FTP(ftplib.FTP):\n\n    def __init__(self, *args, **kwargs):\n        self.source_address = kwargs.pop(\"source_address\", None)\n        ftplib.FTP.__init__(self, *args, **kwargs)\n\n    def connect(self, host='', port=0, timeout=-999, source_address=None):\n        if host != '':\n            self.host = host\n        if port > 0:\n            self.port = port\n        if timeout != -999:\n            self.timeout = timeout\n        if source_address is not None:\n            self.source_address = source_address\n        self.sock = socket.create_connection((self.host, self.port), self.timeout,\n                                             self.source_address)\n        self.af = self.sock.family\n        self.file = self.sock.makefile('rb')\n        self.welcome = self.getresp()\n        return self.welcome\n\n    def ntransfercmd(self, cmd, rest=None):\n        size = None\n        if self.passiveserver:\n            host, port = self.makepasv()\n            conn = socket.create_connection((host, port), self.timeout,\n                                            self.source_address)\n            try:\n                if rest is not None:\n                    self.sendcmd(\"REST %s\" % rest)\n                resp = self.sendcmd(cmd)\n                if resp[0] == '2':\n                    resp = self.getresp()\n                if resp[0] != '1':\n                    raise ftplib.error_reply(resp)\n            except Exception:\n                conn.close()\n                raise\n        else:\n            sock = self.makeport()\n            try:\n                if rest is not None:\n                    self.sendcmd(\"REST %s\" % rest)\n                resp = self.sendcmd(cmd)\n                if resp[0] == '2':\n                    resp = self.getresp()\n                if resp[0] != '1':\n                    raise ftplib.error_reply(resp)\n                conn, sockaddr = sock.accept()\n                if self.timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:\n                    conn.settimeout(self.timeout)\n            finally:\n                sock.close()\n        if resp[:3] == '150':\n            size = ftplib.parse150(resp)\n        return conn, size\n\n\nclass command_ftpget(HoneyPotCommand):\n\n    def help(self):\n        self.write(\"\"\"BusyBox v1.20.2 (2016-06-22 15:12:53 EDT) multi-call binary.\n\nUsage: ftpget [OPTIONS] HOST [LOCAL_FILE] REMOTE_FILE\n\nDownload a file via FTP\n\n    -c Continue previous transfer\n    -v Verbose\n    -u USER     Username\n    -p PASS     Password\n    -P NUM      Port\\n\\n\"\"\")\n\n    def start(self):\n        try:\n            optlist, args = getopt.getopt(self.args, 'cvu:p:P:')\n        except getopt.GetoptError:\n            self.help()\n            self.exit()\n            return\n\n        if len(args) < 2:\n            self.help()\n            self.exit()\n            return\n\n        self.verbose = False\n        self.username = ''\n        self.password = ''\n        self.port = 21\n        self.host = ''\n        self.local_file = ''\n        self.remote_path = ''\n\n        for opt in optlist:\n            if opt[0] == '-v':\n                self.verbose = True\n            elif opt[0] == '-u':\n                self.username = opt[1]\n            elif opt[0] == '-p':\n                self.password = opt[1]\n            elif opt[0] == '-P':\n                try:\n                    self.port = int(opt[1])\n                except ValueError:\n                    pass\n\n        if len(args) == 2:\n            self.host, self.remote_path = args\n        elif len(args) >= 3:\n            self.host, self.local_file, self.remote_path = args[:3]\n\n        self.remote_dir = os.path.dirname(self.remote_path)\n        self.remote_file = os.path.basename(self.remote_path)\n        if not self.local_file:\n            self.local_file = self.remote_file\n\n        fakeoutfile = self.fs.resolve_path(self.local_file, self.protocol.cwd)\n        path = os.path.dirname(fakeoutfile)\n        if not path or not self.fs.exists(path) or not self.fs.isdir(path):\n            self.write('ftpget: can\\'t open \\'%s\\': No such file or directory' % self.local_file)\n            self.exit()\n            return\n\n        self.download_path = CONFIG.get('honeypot', 'download_path')\n\n        self.url_log = 'ftp://'\n        if self.username:\n            self.url_log = '{}{}'.format(self.url_log, self.username)\n            if self.password:\n                self.url_log = '{}:{}'.format(self.url_log, self.password)\n            self.url_log = '{}@'.format(self.url_log)\n        self.url_log = '{}{}'.format(self.url_log, self.host)\n        if self.port != 21:\n            self.url_log = '{}:{}'.format(self.url_log, self.port)\n        self.url_log = '{}/{}'.format(self.url_log, self.remote_path)\n\n        self.artifactFile = Artifact(self.local_file)\n\n        result = self.ftp_download()\n\n        self.artifactFile.close()\n\n        if not result:\n            # log to cowrie.log\n            log.msg(format='Attempt to download file(s) from URL (%(url)s) failed',\n                    url=self.url_log)\n\n            self.protocol.logDispatch(eventid='cowrie.session.file_download.failed',\n                                      format='Attempt to download file(s) from URL (%(url)s) failed',\n                                      url=self.url_log)\n            self.exit()\n            return\n\n        # log to cowrie.log\n        log.msg(format='Downloaded URL (%(url)s) with SHA-256 %(shasum)s to %(outfile)s',\n                url=self.url_log,\n                outfile=self.artifactFile.shasumFilename,\n                shasum=self.artifactFile.shasum)\n\n        self.protocol.logDispatch(eventid='cowrie.session.file_download',\n                                  format='Downloaded URL (%(url)s) with SHA-256 %(shasum)s to %(outfile)s',\n                                  url=self.url_log,\n                                  outfile=self.artifactFile.shasumFilename,\n                                  shasum=self.artifactFile.shasum,\n                                  destfile=self.local_file)\n\n        # Update the honeyfs to point to downloaded file\n        self.fs.mkfile(fakeoutfile, 0, 0, os.path.getsize(self.artifactFile.shasumFilename), 33188)\n        self.fs.update_realfile(self.fs.getfile(fakeoutfile), self.artifactFile.shasumFilename)\n        self.fs.chown(fakeoutfile, self.protocol.user.uid, self.protocol.user.gid)\n\n        self.exit()\n\n    def ftp_download(self):\n        out_addr = ('', 0)\n        if CONFIG.has_option('honeypot', 'out_addr'):\n            out_addr = (CONFIG.get('honeypot', 'out_addr'), 0)\n\n        ftp = FTP(source_address=out_addr)\n\n        # connect\n        if self.verbose:\n            self.write('Connecting to %s\\n' % self.host)  # TODO: add its IP address after the host\n\n        try:\n            ftp.connect(host=self.host, port=self.port, timeout=30)\n        except Exception as e:\n            log.msg('FTP connect failed: host=%s, port=%s, err=%s' % (self.host, self.port, str(e)))\n            self.write('ftpget: can\\'t connect to remote host: Connection refused\\n')\n            return False\n\n        # login\n        if self.verbose:\n            self.write('ftpget: cmd (null) (null)\\n')\n            if self.username:\n                self.write('ftpget: cmd USER %s\\n' % self.username)\n            else:\n                self.write('ftpget: cmd USER anonymous\\n')\n            if self.password:\n                self.write('ftpget: cmd PASS %s\\n' % self.password)\n            else:\n                self.write('ftpget: cmd PASS busybox@\\n')\n\n        try:\n            ftp.login(user=self.username, passwd=self.password)\n        except Exception as e:\n            log.msg('FTP login failed: user=%s, passwd=%s, err=%s' % (self.username, self.password, str(e)))\n            self.write('ftpget: unexpected server response to USER: %s\\n' % str(e))\n            try:\n                ftp.quit()\n            except socket.timeout:\n                pass\n            return False\n\n        # download\n        if self.verbose:\n            self.write('ftpget: cmd TYPE I (null)\\n')\n            self.write('ftpget: cmd PASV (null)\\n')\n            self.write('ftpget: cmd SIZE %s\\n' % self.remote_path)\n            self.write('ftpget: cmd RETR %s\\n' % self.remote_path)\n\n        try:\n            ftp.cwd(self.remote_dir)\n            ftp.retrbinary('RETR %s' % self.remote_file, self.artifactFile.write)\n        except Exception as e:\n            log.msg('FTP retrieval failed: %s' % str(e))\n            self.write('ftpget: unexpected server response to USER: %s\\n' % str(e))\n            try:\n                ftp.quit()\n            except socket.timeout:\n                pass\n            return False\n\n        # quit\n        if self.verbose:\n            self.write('ftpget: cmd (null) (null)\\n')\n            self.write('ftpget: cmd QUIT (null)\\n')\n\n        try:\n            ftp.quit()\n        except socket.timeout:\n            pass\n\n        return True\n\n\ncommands['/usr/bin/ftpget'] = command_ftpget\ncommands['ftpget'] = command_ftpget\n", "path": "src/cowrie/commands/ftpget.py"}]}