不確定是不是版本限制,Python2.7 無法加密連線。
#!/usr/bin/python
#-*- coding:utf-8 -*-
import sys
# FTP
from ftplib import FTP
sFTPhost = '主機網址/IP'
sFTPuser = '帳號'
sFTPpwd = '密碼'
ftp = FTP(sFTPhost, sFTPuser, sFTPpwd)
# ftp = FTP_TLS(sFTPhost, sFTPuser, sFTPpwd)
ftp.cwd("/dir1/dir11") # 切換在 server 的目錄
lstFTPfile = ftp.nlst() # 列出所有檔案
for sFTPfile in lstFTPfile:
print 'sFTPfile = ' + sFTPfile
localfile = open(sFTPfile,'wb') # 本地端要儲存的檔案
ftp.retrbinary('RETR ' + sFTPfile, localfile.write) # 下載檔案
localfile.close()
# 上傳檔案
localfile = open(sFTPfile,'rb')
ftp.cwd("/dir1/dir12") # 切換在 server 的目錄
ftp.storbinary('STOR '+sFTPfile, localfile)
break
ftp.quit
沒有留言:
張貼留言