@ccc thanks for answer and the link
I’m starting from here:
# coding: utf-8
import appex
import console
import os
import ui
from ftplib import FTP
def main():
# Sharing: receive file
fil = appex.get_file_path()
if fil == None:
print('no file passed')
return
server = 'address'
user = 'account'
pwd = 'pass'
server_file = os.path.basename(fil)
try:
ftp = FTP(server) #connect
ftp.encoding = 'utf-8'
ftp.login(user,pwd)
ipad_file = open(fil,'rb')
ftp.storbinary('STOR '+server_file,ipad_file,blocksize=8192)
ipad_file.close()
ftp.close()
except Exception as e:
print(str(e))
appex.finish()
if __name__ == '__main__':
main()
With this code I take a file on OneDrive and upload it to a FTP server, but the code is made for taking files from iOS menu (I think that’s the appex part for the code structure).
Now here it comes the code that @cvp kindly searched and found it points to a web link route, it points to a file through an extracted link (is really awesome, black magic for me...).
As you can see, I’m not a coder, I tried to learn python, bought a book (Learn Python the Hard Way) but got jammed soon. And I have this problem with Pythonista when I search for info about python, the code is tailored for a computer environment, and making it work on Pythonista changes the game a lot.
Sorry I lost focus on this and I’m telling you my sorrows.
I tried to do it in parts first try to understand the code and make it run alone.
import base64
def create_onedrive_directdownload (onedrive_link):
data_bytes64 = base64.b64encode(bytes(onedrive_link, 'utf-8'))
data_bytes64_String = data_bytes64.decode('utf-8').replace('/','_').replace('+','-').rstrip("=")
resultUrl = f"https://api.onedrive.com/v1.0/shares/u!{data_bytes64_String}/root/content"
return resultUrl
I tried to put the OneDrive link on (onedrive_link) I thought it was the first position working as a shortcut but I got an “invalid syntax” error... I’ve noticed that my OneDrive links are not the same as the ones from the article (1drv vs my works personalised direction https:://xxxxxx-my.share point.com/:x:/g/personal/... maybe could be there the issue.
My next step would be to get the file and upload to the FTP address and after that try to make it work with two files and upload the together.
Thanks for your valuable help, I’m a mess with this and I’m trying, for me was a big win to understand the previous code for uploading files from iOS with the script. In the beginning I had to open an ftp app and navigate to the route every time I wanted to upload a file with this script I only have to check that everything worked smoothly, my goal was doing both things on a tap.
I’m asking myself, if I put a Pythonista script pointing to the files I have to upload in the OneDrive folder, would it found them? I suppose this shouldn’t need any route, only file names, am I right?