sftp
paramiko-based sftp sync implementation
connect(uri, timeout=None)
Yield an SFTPClient connected to the server specified by the given URI
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
ParseResult
|
The URI of the EnderChest to connect to |
required |
timeout |
float
|
The number of seconds to wait before timing out the sync operation. If None is provided, no explicit timeout value will be set. |
None
|
Yields:
Type | Description |
---|---|
SFTPClient
|
A Paramiko SFTP client connected to the specified server |
Raises:
Type | Description |
---|---|
ValueError
|
If the URI is invalid or the credentials are incorrect |
RuntimeError
|
If the server cannot be reached |
Source code in enderchest/sync/sftp.py
download_file(client, remote_loc, local_path, remote_stat)
Download a file from a remote SFTP server and save it at the specified location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client |
Paramiko SFTP client
|
An authenticated client connected to the remote server |
required |
remote_loc |
str
|
The POSIX path of the file to download |
required |
local_path |
Path
|
The path to locally save the file |
required |
remote_stat |
stat - like
|
The |
required |
Notes
This is a wrapper around client.get()
that can handle symlinks and
updating timestamps. It does not check if either path is valid, points
to a file, lives in an existing folder, etc.
Source code in enderchest/sync/sftp.py
get_contents(client, path)
Recursively fetch the contents of a remote directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client |
Paramiko SFTP client
|
An authenticated client connected to the remote server |
required |
path |
str
|
The absolute path to scan |
required |
Returns:
Type | Description |
---|---|
list of (Path, SFTPAttributes) tuples
|
The attributes of all files, folders and symlinks found under the specified path |
Notes
- This list is generated via a depth-first search so that all parent directories appear before their children
- The paths returned are relative to the provided path
Source code in enderchest/sync/sftp.py
pull(remote_uri, local_path, exclude, dry_run, timeout=None, delete=True, **unsupported_kwargs)
Sync an upstream file or folder into the specified location SFTP. This will overwrite any files and folders already at the destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_uri |
ParseResult
|
The URI for the remote resource to copy from |
required |
local_path |
Path
|
The destination folder |
required |
exclude |
list of str
|
Any patterns that should be excluded from the sync |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
timeout |
float
|
The number of seconds to wait before timing out the sync operation. If None is provided, no explicit timeout value will be set. |
None
|
delete |
bool
|
Whether part of the syncing should include deleting files at the destination that aren't at the source. Default is True. |
True
|
**unsupported_kwargs |
Any other provided options will be ignored |
{}
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the destination folder does not exist, or if the remote path does not exist |
OSError
|
If the remote path cannot be accessed for any other reason (permissions, most likely) |
Notes
- If the destination folder does not already exist, this method will not create it or its parent directories.
Source code in enderchest/sync/sftp.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
|
push(local_path, remote_uri, exclude, dry_run, timeout=None, delete=True, **unsupported_kwargs)
Sync a local file or folder into the specified location using SFTP. This will overwrite any files and folders already at the destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_path |
Path
|
The file or folder to copy |
required |
remote_uri |
ParseResult
|
The URI for the remote location to copy into |
required |
exclude |
list of str
|
Any patterns that should be excluded from the sync |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
timeout |
float
|
The number of seconds to wait before timing out the sync operation. If None is provided, no explicit timeout value will be set. |
None
|
delete |
bool
|
Whether part of the syncing should include deleting files at the destination that aren't at the source. Default is True. |
True
|
**unsupported_kwargs |
Any other provided options will be ignored |
{}
|
Notes
- If the destination folder does not already exist, this method will not create it or its parent directories.
Source code in enderchest/sync/sftp.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
|
rglob(client, path)
Recursively enumerate the contents of a remote directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client |
Paramiko SFTP client
|
An authenticated client connected to the remote server |
required |
path |
str
|
The absolute path to scan |
required |
Returns:
Type | Description |
---|---|
list of (Path, SFTPAttributes) tuples
|
The attributes of all files, folders and symlinks found under the specified path |
Notes
- The paths returned are absolute
- The search is performed depth-first
Source code in enderchest/sync/sftp.py
upload_file(client, local_path, remote_loc)
Upload a local file to a remote SFTP server
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client |
Paramiko SFTP client
|
An authenticated client connected to the remote server |
required |
local_path |
Path
|
The path of the file to upload |
required |
remote_loc |
str
|
The POSIX path for the remote location to save the file |
required |
Notes
This is just a wrapper around client.put()
that can handle symlinks.
It does not check if either path is valid, points to a file, lives in an
existing folder, etc.