[Tutor] sftp get single file
Sander Sweers
sander.sweers at gmail.com
Fri Jul 17 17:42:35 CEST 2009
2009/7/17 Matt Herzog <msh at blisses.org>:
> Hello All.
>
> I need to use paramiko to sftp get a single file from a remote server.
> The remote file's base name will be today's date (%Y%m%d) dot tab.
> I need help joining the today with the .tab extension. Do I need globbing?
>
> example: 20090716.tab
>
> #!/usr/bin/env python
> import paramiko
> import glob
> import os
> import time
> hostname = 'sftp.booboo.com'
> port = 22
> username = 'booboo'
> password = '07N4219?'
> # glob_pattern='*.tab'
> today = time.strftime("%Y%m%d")
> remotepath = today.tab
> localpath = '/home/data/text'
>
> if __name__ == "__main__":
> t = paramiko.Transport((hostname, port))
> t.connect(username=username, password=password)
> sftp = paramiko.SFTPClient.from_transport(t)
> sftp.get(remotepath, localpath)
> t.close()
> --
You don't need glob if you know in advance what the filename is. Print
example below.
---
import time
today = time.localtime()
datestr = time.strftime("%Y%m%d",today)
ext = ".tab"
print datestr + ext
---
Greets
Sander
More information about the Tutor
mailing list