FedericoSala
FedericoSala

Reputation: 168

Python - move and read .txt files from Windows folder to Linux server

I'd need to read and move some .txt files from a windows server (eg. 192.168.xxx.xxx\Share) to a folder in my Linux server where the script should run in crontab.

Is there a smart way to do it? I'm thinking something like below

    import paramiko


def move_txt_file_task():
    try:
        ssh_client =paramiko.SSHClient()
        ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_client.connect(hostname='192.168.xxx.xxx',username='xxx',password='xxx')

        ftp_client=ssh.open_sftp()
        ftp_client.put('/root/giles/test','\\192.168.xxx.xxx\Doc-Share\Log')
        ftp_client.close()

    except paramiko.SSHException:
        logging.info("Invalid Username/Password")

But I get this error:

> paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on 192.168.xxx.xxx

Upvotes: 0

Views: 126

Answers (1)

balderman
balderman

Reputation: 23815

Use paramiko in order to transfer file to the linux machine.

See more here.

ftp_client=ssh.open_sftp()
ftp_client.put(‘localfilepath’,remotefilepath’)
ftp_client.close()

Upvotes: 1

Related Questions