0

I would like to upload two files to my FTP server once a day for a month via a Python script. I want to use sleep(60*60*24) to wait for the next day, but I don't know how to actually upload my files.

I know about ftplib, but I could not find any documentation that helped me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

2

Something like this should work:

#!/usr/bin/python
import ftplib
from time import sleep

while True:
    IP = "xx.xx.xx.xx"
    path_file1 = "./MyFile1.py"
    path_file2 = "./MyFile2.py"

    UID = ""
    PSW = ""

    ftp = ftplib.FTP(IP)
    ftp.login(UID, PSW)
    ftp.cwd("/Unix/Folder/where/I/want/to/put/file")

    with open(path_file1, 'r') as myfile: ftp.storlines('STOR ' + filename, myfile)
    with open(path_file2, 'r') as myfile: ftp.storlines('STOR ' + filename, myfile)

    sleep(86400)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Liam
  • 6,009
  • 4
  • 39
  • 53