Hi i'm stuck on this script that i'm busy writing and have no idea where to start. I need a script that connects to a secure ftp, downloads files and store it on my local pc. has anyone done something similar and which modules should i be looking at.

Dani AI

Generated

Quick, practical guidance for (and thanks to for pointing toward SFTP tooling):

SFTP is an SSH service, not the same as FTP — the stdlib ftplib is for plain FTP, so use a third-party client. For simple, blocking scripts try a small client like pysftp (installable via pip) and for asyncio-based programs look at AsyncSSH for nonblocking IO (pysftp on PyPI , AsyncSSH docs , Python FTP docs for contrast: ftplib).

Recommended workflow and troubleshooting

  • Pick the library that matches your app (sync vs async).
  • Verify host keys: add the server key to your ~/.ssh/known_hosts instead of disabling checks.
  • Choose authentication: password or private key (key-based is preferred for automation).
  • Start by listing a remote directory, filter filenames, then download each file to a local directory and verify (checksum or size).
  • Common problems: wrong port (SFTP often uses 22 but can be different), firewall blocks, incorrect credentials, or missing SFTP subsystem on server.

Minimal example (pysftp) showing host-key verification and downloading files:

import os
from pathlib import Path
import pysftp

KNOWN = os.path.expanduser("~/.ssh/known_hosts")
cnopts = pysftp.CnOpts()
cnopts.hostkeys.load(KNOWN)   # ensures host key is known

with pysftp.Connection('sftp.example.com', username='me', password='secret', cnopts=cnopts) as s:
    s.chdir('/remote/path')
    local_dir = Path('/local/path')
    for fname in s.listdir():
        if fname.endswith('.txt'):
            s.get(fname, str(local_dir / fname))

Quick tip: add the host key with ssh-keyscan -p 22 sftp.example.com >> ~/.ssh/known_hosts (or connect once interactively and accept the key). Avoid setting hostkey checks off in production.

Recommended Answers

All 2 Replies

i think thats the first site i've checked although i think that's for uploading a file. i'll have a look at paramiko and see what i can conjure.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.