[Tutor] sftp get single file

Johan Geldenhuys johan at accesstel.com.au
Wed Jun 22 08:55:41 CEST 2011


Hi all,
This topic is old, but I have a similar issue and I know everybody will say I should use piramiko, but it is not that simple.

The device I have to run my python scripts on is a simple, small, scaled down version of Suse linux and I can't install other packages like piramiko.
All the files I need to use that is not part of Python 2.7 must be included in my package.

With the above in mind, what can I use to open SFTP to a server and transfer a file?

Thanks

Johan


-----Original Message-----
From: tutor-bounces+johan=accesstel.com.au at python.org [mailto:tutor-bounces+johan=accesstel.com.au at python.org] On Behalf Of Sander Sweers
Sent: Saturday, 18 July 2009 1:43 AM
To: Matt Herzog
Cc: Python List
Subject: Re: [Tutor] sftp get single file

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
_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor

Checked by AVG - www.avg.com 
Version: 8.5.387 / Virus Database: 270.13.17/2242 - Release Date: 07/16/09 18:00:00



More information about the Tutor mailing list