0

I am using pysftp on Python and am trying to run a loop for a certain directory in the sftp server.

I don't know how to write the directory paths on sftp servers. I thought that connecting to the server and just writing the directory as below would work, but it doesn't. Please let me know how to write sftp paths so that python can read them.

sftp =  pysftp.Connection('128.59.164.112', username = '', password = '');
source = sftp.u\'weatherForecast\'/dataRAW/2004/grib/tmax/
2
  • Do you get an error? Commented Feb 9, 2015 at 4:23
  • I got a syntax errors before, but now I found a solution. Commented Feb 9, 2015 at 5:00

2 Answers 2

1

Try this:

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

You should read this: http://pysftp.readthedocs.org/en/latest/index.html

PS1: ; is optional in Python, but not Pythonic.

Sign up to request clarification or add additional context in comments.

Comments

0

After enough trial and error I figured it out.

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

This works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.