【问题标题】:Python script that uploads a file to an FTP server once a day [closed]每天一次将文件上传到 FTP 服务器的 Python 脚本[关闭]
【发布时间】:2018-01-12 04:02:18
【问题描述】:
我想通过 Python 脚本在一个月内每天一次将两个文件上传到我的 FTP 服务器。我想使用sleep(60*60*24) 等待第二天,但我不知道如何实际上传我的文件。
我知道ftplib,但我找不到任何对我有帮助的文档。
【问题讨论】:
标签:
python
file-upload
ftp
upload
multiple-file-upload
【解决方案1】:
这样的事情应该可以工作:
#!/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)