Pythonista is an app that makes your iOS device powerful. Not to mention serverization, various other things are possible.
Furthermore, it can be executed not only in Python 2.7 but also in Python 3.5. Not only can you write Python code, but you can't beat the original keyboard, terminal (console), editor, extensions, etc ...
Move on to the code description.
FTP.py
# coding=utf-8
#############################
# FileName: FTP.py
#.
#├── FTP.py
#└── var
# └── tmp
# └── test.html
#############################
## improt
from ftplib import FTP_TLS
##variable variable
ftp_serveraddress = 'ftp address'
ftp_user = 'account name'
ftp_password = 'password'
ftp_putdir = './var/tmp/'
ftp_putfile = 'test.html'
def ftpput(host, username, password, putdir, putfile):
try:
ftp_putdir = "/"
_putfile = '%s%s' % (putdir, putfile)
print _putfile
print "FTP Start."
#For FTP
# _ftp = FTP(host) #FTP communication
_ftps = FTP_TLS(host) #FTPS communication
#Debug log output(0:None/1:command/2:Details)
_ftps.set_debuglevel(1) #You can check the debug log in real time.
_ftps.login(username, password)
print _ftps.getwelcome()
print "Login OK! : %s" % (_ftps)
_ftps.cwd(ftp_putdir)
print "File Open."
_file = open(_putfile, 'rb')
command = 'STOR %s' % putfile #Because command operation is required
_ftps.storlines(command, _file)
_file.close()
print _ftps.quit()
print "File UP Complete!"
except:
_ftps.quit()
print "ERR!! ftpput_failed :" + _putfile
if __name__ == '__main__':
ftpput(ftp_serveraddress, ftp_user, ftp_password, ftp_putdir, ftp_putfile)
You now have a simple FTP client. The place where the file is specified is not cool, but ...
The challenge this time is that it is possible to communicate with FTPS instead of FTP communication. I would like to make the next application considering the UI etc. so that the user side will be comfortable.
If you upload a file with the same name, it will be overwritten.
Recommended Posts