Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.1 kB
1
Indexable
Never
import pysftp

def upload_file_to_sftp(local_path, remote_path, host, username, password, port=22):
    with pysftp.Connection(host, username=username, password=password, port=port) as sftp:
        sftp.put(local_path, remote_path)
        print(f"File {local_path} berhasil diupload ke {remote_path}")

def download_file_from_sftp(remote_path, local_path, host, username, password, port=22):
    with pysftp.Connection(host, username=username, password=password, port=port) as sftp:
        sftp.get(remote_path, local_path)
        print(f"File {remote_path} berhasil didownload ke {local_path}")

# Contoh penggunaan
local_file_path = "local_file.txt"
remote_file_path = "/path/to/remote_file.txt"
sftp_host = "your_sftp_host"
sftp_username = "your_sftp_username"
sftp_password = "your_sftp_password"

# Upload file ke SFTP
upload_file_to_sftp(local_file_path, remote_file_path, sftp_host, sftp_username, sftp_password)

# Download file dari SFTP
downloaded_file_path = "downloaded_file.txt"
download_file_from_sftp(remote_file_path, downloaded_file_path, sftp_host, sftp_username, sftp_password)
Leave a Comment