[Tutor] Passing command line argument in function

Liam Clarke cyresse at gmail.com
Tue Jun 14 07:40:16 CEST 2005


What path is the file? 

On 6/14/05, Gary Taylor <squeaky at sdf.lonestar.org> wrote:
> 
> I'm trying to pass the name of a file as the first argument
> to the ftp.storbinary function(?) below. The only thing I
> can get to work is the real file name hard coded as the
> argument. I've tried parenthesis, single quotes, double
> quotes, and many combinations of the previous. I've tried
> passing sys.argv[1] directly as well, although with fewer
> experiments.
> 
> I invoke this as below and the output is what I would
> expect, but the file name on the ftp server is never
> correct.
> 
> 
> What is the correct way to do this?
> 
> 
> $ ./garyftp.py align.ps <http://align.ps>
> align.ps <http://align.ps>
> 
> 
> 
> ---
> Python 2.3.4 on Linux.
> 
> 
> ---
> #!/usr/bin/python
> import sys
> from ftplib import FTP
> 
> file_to_transfer = sys.argv[1]
> 
> ftp = FTP()
> ftp.connect("myserver")
> ftp.login("myusername", "mypasswd")
> 
> 
> ftp.storbinary(stor file_to_transfer, open(file_to_transfer,"r"))
> 
> print file_to_transfer
> ftp.quit()
> --
> 
> Thanks,
> Gary
> 
> squeaky at sdf.lonestar.org
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



-- 
'There is only one basic human right, and that is to do as you damn well 
please.
And with it comes the only basic human duty, to take the consequences.'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050614/5a9e31d6/attachment.htm


More information about the Tutor mailing list