Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. # coding=utf-8
  2. #############################
  3. # FileName: test.py
  4. #.
  5. #├── test.py
  6. #└── var
  7. # └── tmp
  8. # └── test.html
  9. #############################
  10. ## improt
  11. from ftplib import FTP_TLS
  12.  
  13. ## variable 変数
  14. ftp_serveraddress = 'ftpアドレス'
  15. ftp_user = 'アカウント名'
  16. ftp_password = 'パスワード'
  17. ftp_putdir = './var/tmp/'
  18. ftp_putfile = 'test.html'
  19.  
  20. def ftpput(host, username, password, putdir, putfile):
  21. try:
  22. ftp_putdir = "/"
  23. _putfile = '%s%s' % (putdir, putfile)
  24. print _putfile
  25. print "FTP Start."
  26. # FTPの場合
  27. # _ftp = FTP(host) # FTP通信
  28. _ftps = FTP_TLS(host) # FTPS通信
  29. # デバックログの出力 (0:なし /1:コマンド /2:詳細)
  30. _ftps.set_debuglevel(1) # デバッグログがリアルタイムで確認できます。
  31. _ftps.login(username, password)
  32. print _ftps.getwelcome()
  33. print "Login OK! : %s" % (_ftps)
  34. _ftps.cwd(ftp_putdir)
  35. print "File Open."
  36. _file = open(_putfile, 'rb')
  37. command = 'STOR %s' % putfile # command操作が必要なため
  38. _ftps.storlines(command, _file)
  39. _file.close()
  40. print _ftps.quit()
  41. print "File UP Complete!"
  42. except:
  43. _ftps.quit()
  44. print "ERR!! ftpput_failed :" + _putfile
  45.  
  46. if __name__ == '__main__':
  47. ftpput(ftp_serveraddress, ftp_user, ftp_password, ftp_putdir, ftp_putfile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement