2015-02-09 105 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。