2015-02-09 104 views
0

我在Python上使用pysftp,我試圖爲sftp服務器中的某個目錄運行一個循環。sftp服務器的寫入路徑python

我不知道如何在sftp服務器上編寫目錄路徑。我認爲,連接到服務器,只是寫下如下目錄將工作,但事實並非如此。請讓我知道如何編寫sftp路徑,以便python可以讀取它們。

sftp = pysftp.Connection('128.59.164.112', username = '', password = ''); 
source = sftp.u\'weatherForecast\'/dataRAW/2004/grib/tmax/ 
+0

你有錯誤嗎? – paulmelnikow 2015-02-09 04:23:17

+0

我之前得到了一個語法錯誤,但現在我找到了一個解決方案。 – rokman54 2015-02-09 05:00:14

回答

0

經過足夠的試驗和錯誤,我找到了答案。

source = 'weatherForecast/dataRAW/2004/grib/tmax/' 
destination= 'sftp.u\'weatherForecast\'/csv/2004/tmax' 

This works。

1

試試這個:

import pysftp 

sftp = pysftp.Connection('hostname', username='me', password='secret') 
sftp.chdir('/home/user/development/stackoverflow') 
ls = sftp.listdir() 
for filename in ls: 
    print filename 

你應該閱讀:http://pysftp.readthedocs.org/en/latest/index.html

PS1:;在Python中是可選的,但不是Pythonic。