3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonistaでFTPアップロードする

Posted at

Pythonistaを使って、iPhone内の写真をFTPでアップロードするスクリプトを作成しました。
https://itunes.apple.com/jp/app/pythonista-3/id1085978097?mt=8

ホスト名とかはconfigparser使ったほうがいいとは思うのだけれど...

import os
import ftplib
import photos
from objc_util import ObjCInstance

# ***************************************************************
HOSTNAME = 'FTPホスト名'
USERNAME = 'FTPユーザ名'
PASSWORD = 'FTPパスワード'
UPLOAD_DIST = 'アップロード先'  # exp: '/var/www/html/wordpress/wp-content/uploads/'
# ***************************************************************


def ftp_upload(filenames):
	ftp = ftplib.FTP(HOSTNAME)
	ftp.set_pasv('true')
	ftp.login(USERNAME, PASSWORD)
	for file in filenames:
		fp = open(file, 'rb')
		ftp.storbinary('STOR ' + UPLOAD_DIST + os.path.basename(file), fp)
		fp.close()
	ftp.close()

def get_photo_filenames():
	p_list = photos.pick_asset(title='写真を選択', multi=True)
	if p_list is not None:
		filenames = []
		for p in p_list:
			file_name = str(ObjCInstance(p).valueForKey_('filename'))
			P=ObjCInstance(p)
			filenames.append(str(P.pathForOriginalFile()))
		return filenames
	
if __name__ == '__main__':
	ftp_upload(get_photo_filenames())
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?