Connect to host. Arguments are: - host: hostname to connect to (string, default previous host) - port: port to connect to (integer, default previous port) - timeout: the timeout to set against the ftp socket(s) - source_address: a 2-tuple (host, port) for the soc
(self, host='', port=0, timeout=-999, source_address=None)
| 137 | self.close() |
| 138 | |
| 139 | def connect(self, host='', port=0, timeout=-999, source_address=None): |
| 140 | '''Connect to host. Arguments are: |
| 141 | - host: hostname to connect to (string, default previous host) |
| 142 | - port: port to connect to (integer, default previous port) |
| 143 | - timeout: the timeout to set against the ftp socket(s) |
| 144 | - source_address: a 2-tuple (host, port) for the socket to bind |
| 145 | to as its source address before connecting. |
| 146 | ''' |
| 147 | if host != '': |
| 148 | self.host = host |
| 149 | if port > 0: |
| 150 | self.port = port |
| 151 | if timeout != -999: |
| 152 | self.timeout = timeout |
| 153 | if self.timeout is not None and not self.timeout: |
| 154 | raise ValueError('Non-blocking socket (timeout=0) is not supported') |
| 155 | if source_address is not None: |
| 156 | self.source_address = source_address |
| 157 | sys.audit("ftplib.connect", self, self.host, self.port) |
| 158 | self.sock = socket.create_connection((self.host, self.port), self.timeout, |
| 159 | source_address=self.source_address) |
| 160 | self.af = self.sock.family |
| 161 | self.file = self.sock.makefile('r', encoding=self.encoding) |
| 162 | self.welcome = self.getresp() |
| 163 | return self.welcome |
| 164 | |
| 165 | def getwelcome(self): |
| 166 | '''Get the welcome message from the server. |