Python 每天将文件上传到 FTP 服务器一次的脚本
Python script that uploads a file to an FTP server once a day
我想通过 Python 脚本每天一次将两个文件上传到我的 FTP 服务器一个月。我想用sleep(60*60*24)
等待第二天,但我不知道如何真正上传我的文件。
我知道 ftplib
,但我找不到任何对我有帮助的文档。
像这样的东西应该可以工作:
#!/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)
我想通过 Python 脚本每天一次将两个文件上传到我的 FTP 服务器一个月。我想用sleep(60*60*24)
等待第二天,但我不知道如何真正上传我的文件。
我知道 ftplib
,但我找不到任何对我有帮助的文档。
像这样的东西应该可以工作:
#!/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)