HELP - FTP seesions using python????????

gony at my-dejanews.com gony at my-dejanews.com
Tue Apr 27 23:14:27 EDT 1999


thanks for the samples

I'll work my way through them and figure out what they do and how they do it

another small question in perl the #!/usr/local/bin/perl is not needed when
run on a windows machine, does it matter for Python on a windows machine
whether this line is present or not?


In article <aahzFAtrsr.L3w at netcom.com>,
  aahz at netcom.com (Aahz Maruch) wrote:
> In article <7g328l$hga$1 at nnrp1.dejanews.com>,  <gony at my-dejanews.com> wrote:
> >
> >any links or tips etc on how to tackle automation of FTP sessions using
python
> >would be most appreciated.
>
> Here's a sample; there aren't any comments (proof that Python can be
> almost as obscure as Perl ;-), but it shouldn't be *that* hard to read:
>
> #!/usr/local/bin/python
>
> import sys, os, ftplib, string
>
> def getpass(prompt = "Password: "):
>     import termios, TERMIOS, sys
>     fd = sys.stdin.fileno()
>     old = termios.tcgetattr(fd)
>     new = termios.tcgetattr(fd)
>     new[3] = new[3] & ~TERMIOS.ECHO          # lflags
>     try:
>         termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
>         passwd = raw_input(prompt)
>     finally:
>         termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
> 	print
>     return passwd
>
> if len ( sys.argv ) < 4 :
> 	raise 'Must have three arguments: host[:path], user[:passwd], and file'
>
> HostPath = sys.argv[1]
> pos = string.find ( HostPath, ':' )
> if pos > 0 :
> 	host = HostPath[0:pos]
> 	if ( pos + 1 ) == len ( HostPath ) :
> 		path = ""
> 	else:
> 		path = HostPath[(pos+1):]
> else :
> 	host = HostPath
> 	path = ""
>
> UserPass = sys.argv[2]
> pos = string.find ( UserPass, ':' )
> if pos > 0 :
> 	user = UserPass[0:pos]
> 	if ( pos + 1 ) == len ( UserPass ) :
> 		passwd = ""
> 	else:
> 		passwd = UserPass[(pos+1):]
> else :
> 	user = UserPass
> 	passwd = getpass()
>
> filename = sys.argv[3]
> pos = string.rfind ( filename, '/' )
> if pos > 0 :
> 	basename = filename[pos:]
> else :
> 	basename = filename
>
> fd = open ( filename )
> ftp = ftplib.FTP ( host, user, passwd )
> ftp.cwd ( path )
> ftp.storbinary ( 'STOR %s' % basename, fd, 1024 * 16 )
> ftp.close()
>
> fd.close()
> --
>                       --- Aahz (@netcom.com)
>
> Hugs and backrubs -- I break Rule 6       <*>      http://www.rahul.net/aahz/
> Androgynous poly kinky vanilla queer het
>
> Hi!  I'm a beta for SigVirus 2000!  Copy me into your .sigfile!
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




More information about the Python-list mailing list