;-( grace period now expired, and upload mandatorily to be changed to sftp-application .......
[Addition March15, 2021:
Apparently problems between Strato and it's Customers to get SFTP up & running for the usual applications.
FTP-functionality is still active at this moment:
under 'SFTP-Management' it is possible to select either SFTP, FTP, or the combination of both]
Below python-script performs required ftp-upload without much hazzle, in this version for upload of a file for AWEKAS.
Just puzzled how to change this script for application with sftp.
It is not sufficient to change <ftp_servername> towards the new sftp-servername.
The 'problem' can pragmatically be solved under application of external Windows' sync- or SFTP-software ( as described at
website Raspberry.org) and at many other websites.
My own variant is the application of sync-software AllwaySync which has multiple capabilities for upload & download:
only one negative aspect is that this software uses fixed values for intervals.
That has the consequence that peakloads may occur on 'nice' times such as whole hour, half hour etc. => 'trouble'
WinSCP's Sync is better in that perspective, but the Sync-function of that program has other weaknesses.
Prefered to have an integrated Linux-solution running in Domoticz, Python etc. as part of the application (or using an SFTP-server at that same Raspberry) for below argumentation.
As example, for periodic upload of files to a destination, an external SFTP-software has to pull the designated files from the Raspberry on which the application is running.
If you have various Raspberries, it means that the external software must periodically poll the Raspberries, and the external software is a nodal point (= single point of failure) in the route to the destination. To avoid/suppress the problem described in the first section, the external software should be able to poll at flexibly variable times and must have high transferspeed, because otherwise a 'choking point' in time, not only at the external software, but also at the Raspberries.
To reduce the latter aspect, it would be nice if each application at Raspberry would have it's own 'pushing' SFTP-uploadfunction
= per Raspberry&application an independent timing & channel for upload => each with relatively low volume, purposely spread over time, not only at 'nice' times, but also at 'odd' times.
Linux has an SFTP-command, but that seems for commandline only: while my application is aimed at an automated script for periodic upload etc..
Anybody experience/hints/alternatives to convert the below script into an SFTP-variant?
No preference for programming language: Python-application is nice, but if alternative setups exists as lua-script, as dzVents-script, or as PHP-script, equally welcome
Code: Select all
#!/usr/bin/python
# -*- coding = utf-8 to enable reading by simple editors -*-
# (c)2017 script compiled by Toulon7559 from various material from forums, version 0.2 for upload of awekas_wl.html
# --------------------------------------------------
# Line005 = PREPARATION & SETTING
# --------------------------------------------------
# Assure that ftplib has been installed, and make this script part of cronjob for periodic execution
# This script assumes the html-file to be saved to folder /home/pi/
# This script uploads the html-file to the root-folder of the remote ftp-server
# Lines 32 and 33 to be filled with your applicable account-info for the ftp-account
# Linenumbers and Printlines are for testing.
print
print ('Start of script')
# --------------------------------------------------
# Line016 = Function for FTP_UPLOAD to Server
# --------------------------------------------------
# Imports for script-operation
import ftplib
import os
# Definition of Upload_function
def upload(ftp, file):
ext = os.path.splitext(file)[1]
if ext in (".txt", ".htm", ".html"):
ftp.storlines("STOR " + file, open(file))
else:
ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
# --------------------------------------------------
# Line030 = Actual FTP-Login & -Upload
# --------------------------------------------------
ftp = ftplib.FTP("<ftp_servername>")
ftp.login("<ftp_username>", "<ftp_password>")
upload(ftp, "awekas_wl.html")
print ('End of script')