Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding=utf-8
- #############################
- # FileName: test.py
- #.
- #├── test.py
- #└── var
- # └── tmp
- # └── test.html
- #############################
- ## improt
- from ftplib import FTP_TLS
- ## variable 変数
- ftp_serveraddress = 'ftpアドレス'
- ftp_user = 'アカウント名'
- ftp_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."
- # FTPの場合
- # _ftp = FTP(host) # FTP通信
- _ftps = FTP_TLS(host) # FTPS通信
- # デバックログの出力 (0:なし /1:コマンド /2:詳細)
- _ftps.set_debuglevel(1) # デバッグログがリアルタイムで確認できます。
- _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 # command操作が必要なため
- _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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement