2017-10-28 166 views
-1

我爲學校項目創建了一個.tiff圖像生成器,它在我的電腦上運行得非常好!在FTP上保存創建的圖像?

此生成器現在在ftp服務器上,它生成.tiff,並將其保存在ftp以便能夠被下載。 但它不起作用。當用戶點擊指定的按鈕「生成」時,我用函數php exec()或system()調用我的python腳本 你知道如何使用我的python腳本將我的img .tiff保存在ftp服務器上嗎?

謝謝你的回答,對不起我的英文,我是法國人。


img = Image.fromarray(data, 'CMYK') #Make image from matrix 
ftp = FTP('wbe-site', 'Identifiant', 'Password') #it's changed in my 
code 
etat = ftp.getwelcome() 
print("Etat : ", etat) 
f = open(img, 'rb')  # Open the image 
ftp.storbinary('STOR carte.tiff', f) #Save file on FTP 
f.close()         # Close the file 
ftp.quit() 

回答

2

如果使用FTPLIB您可以使用此代碼:

import ftplib 
session = ftplib.FTP('server.address.com','USERNAME','PASSWORD') 
file = open('kitten.jpg','rb')     # file to send 
session.storbinary('STOR kitten.jpg', file)  # send the file 
file.close()         # close file and FTP 
session.quit() 

您正在打開的圖像,不給open函數的字符串。

+0

你好男人,看看我的代碼,這是我做的:p – florian

+0

你有ftplib導入嗎?你還有什麼錯誤? –

+0

是FTPLIB是進口的;) 在這裏你可以看到我的錯誤信息: 回溯(最近通話最後一個): 文件 「./generation.py」,行96,在 tiffEnCouleurs(fichier)\t \t \t \t #function使文件 文件 「./generation.py」,線86,在tiffEnCouleurs F =開放(IMG, 'RB')\t \t \t #opening文件.TIFF 類型錯誤:強迫爲Unicode:需要字符串或緩衝區,找到圖像 – florian