Format: application/octet-stream
1 import sys
2 from _typeshed import SupportsRead, SupportsReadline
3 from socket import socket
4 from ssl import SSLContext
5 from types import TracebackType
6 from typing import Any, BinaryIO, Callable, Dict, Iterable, Iterator, List, Optional, Text, TextIO, Tuple, Type, TypeVar, Union
7 from typing_extensions import Literal
8
9 _T = TypeVar("_T")
10 _IntOrStr = Union[int, Text]
11
12 MSG_OOB: int
13 FTP_PORT: int
14 MAXLINE: int
15 CRLF: str
16 if sys.version_info >= (3,):
17 B_CRLF: bytes
18
19 class Error(Exception): ...
20 class error_reply(Error): ...
21 class error_temp(Error): ...
22 class error_perm(Error): ...
23 class error_proto(Error): ...
24
25 all_errors = Tuple[Type[Exception], ...]
26
27 class FTP:
28 debugging: int
29
30 # Note: This is technically the type that's passed in as the host argument. But to make it easier in Python 2 we
31 # accept Text but return str.
32 host: str
33
34 port: int
35 maxline: int
36 sock: Optional[socket]
37 welcome: Optional[str]
38 passiveserver: int
39 timeout: int
40 af: int
41 lastresp: str
42
43 if sys.version_info >= (3,):
44 file: Optional[TextIO]
45 encoding: str
46 def __enter__(self: _T) -> _T: ...
47 def __exit__(
48 self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
49 ) -> None: ...
50 else:
51 file: Optional[BinaryIO]
52
53 if sys.version_info >= (3, 3):
54 source_address: Optional[Tuple[str, int]]
55 def __init__(
56 self,
57 host: Text = ...,
58 user: Text = ...,
59 passwd: Text = ...,
60 acct: Text = ...,
61 timeout: float = ...,
62 source_address: Optional[Tuple[str, int]] = ...,
63 ) -> None: ...
64 def connect(
65 self, host: Text = ..., port: int = ..., timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...
66 ) -> str: ...
67 else:
68 def __init__(
69 self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., timeout: float = ...
70 ) -> None: ...
71 def connect(self, host: Text = ..., port: int = ..., timeout: float = ...) -> str: ...
72 def getwelcome(self) -> str: ...
73 def set_debuglevel(self, level: int) -> None: ...
74 def debug(self, level: int) -> None: ...
75 def set_pasv(self, val: Union[bool, int]) -> None: ...
76 def sanitize(self, s: Text) -> str: ...
77 def putline(self, line: Text) -> None: ...
78 def putcmd(self, line: Text) -> None: ...
79 def getline(self) -> str: ...
80 def getmultiline(self) -> str: ...
81 def getresp(self) -> str: ...
82 def voidresp(self) -> str: ...
83 def abort(self) -> str: ...
84 def sendcmd(self, cmd: Text) -> str: ...
85 def voidcmd(self, cmd: Text) -> str: ...
86 def sendport(self, host: Text, port: int) -> str: ...
87 def sendeprt(self, host: Text, port: int) -> str: ...
88 def makeport(self) -> socket: ...
89 def makepasv(self) -> Tuple[str, int]: ...
90 def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ...) -> str: ...
91 # In practice, `rest` rest can actually be anything whose str() is an integer sequence, so to make it simple we allow integers.
92 def ntransfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> Tuple[socket, int]: ...
93 def transfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> socket: ...
94 def retrbinary(
95 self, cmd: Text, callback: Callable[[bytes], Any], blocksize: int = ..., rest: Optional[_IntOrStr] = ...
96 ) -> str: ...
97 def storbinary(
98 self,
99 cmd: Text,
100 fp: SupportsRead[bytes],
101 blocksize: int = ...,
102 callback: Optional[Callable[[bytes], Any]] = ...,
103 rest: Optional[_IntOrStr] = ...,
104 ) -> str: ...
105 def retrlines(self, cmd: Text, callback: Optional[Callable[[str], Any]] = ...) -> str: ...
106 def storlines(self, cmd: Text, fp: SupportsReadline[bytes], callback: Optional[Callable[[bytes], Any]] = ...) -> str: ...
107 def acct(self, password: Text) -> str: ...
108 def nlst(self, *args: Text) -> List[str]: ...
109 # Technically only the last arg can be a Callable but ...
110 def dir(self, *args: Union[str, Callable[[str], None]]) -> None: ...
111 if sys.version_info >= (3, 3):
112 def mlsd(self, path: Text = ..., facts: Iterable[str] = ...) -> Iterator[Tuple[str, Dict[str, str]]]: ...
113 def rename(self, fromname: Text, toname: Text) -> str: ...
114 def delete(self, filename: Text) -> str: ...
115 def cwd(self, dirname: Text) -> str: ...
116 def size(self, filename: Text) -> Optional[int]: ...
117 def mkd(self, dirname: Text) -> str: ...
118 def rmd(self, dirname: Text) -> str: ...
119 def pwd(self) -> str: ...
120 def quit(self) -> str: ...
121 def close(self) -> None: ...
122
123 class FTP_TLS(FTP):
124 def __init__(
125 self,
126 host: Text = ...,
127 user: Text = ...,
128 passwd: Text = ...,
129 acct: Text = ...,
130 keyfile: Optional[str] = ...,
131 certfile: Optional[str] = ...,
132 context: Optional[SSLContext] = ...,
133 timeout: float = ...,
134 source_address: Optional[Tuple[str, int]] = ...,
135 ) -> None: ...
136 ssl_version: int
137 keyfile: Optional[str]
138 certfile: Optional[str]
139 context: SSLContext
140 def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ..., secure: bool = ...) -> str: ...
141 def auth(self) -> str: ...
142 def prot_p(self) -> str: ...
143 def prot_c(self) -> str: ...
144 if sys.version_info >= (3, 3):
145 def ccc(self) -> str: ...
146
147 if sys.version_info < (3,):
148 class Netrc:
149 def __init__(self, filename: Optional[Text] = ...) -> None: ...
150 def get_hosts(self) -> List[str]: ...
151 def get_account(self, host: Text) -> Tuple[Optional[str], Optional[str], Optional[str]]: ...
152 def get_macros(self) -> List[str]: ...
153 def get_macro(self, macro: Text) -> Tuple[str, ...]: ...
154
155 def parse150(resp: str) -> Optional[int]: ... # undocumented
156 def parse227(resp: str) -> Tuple[str, int]: ... # undocumented
157 def parse229(resp: str, peer: Any) -> Tuple[str, int]: ... # undocumented
158 def parse257(resp: str) -> str: ... # undocumented
159 def ftpcp(
160 source: FTP,
161 sourcename: str,
162 target: FTP,
163 targetname: str = ...,
164 type: Literal["A", "I"] = ...,
165 ) -> None: ... # undocumented
166