Using variable in storbinary function of ftpilb module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arya, Manish Kumar

    Using variable in storbinary function of ftpilb module

    Hi,

    I am new to python.

    I have written a simple code to upload a file via ftp to remote server

    -------------
    import sys
    import ftplib
    host=sys.argv[1]
    username=sys.ar gv[2]
    passwd=sys.argv[3]
    filename=sys.ar gv[4]

    print host,username,p asswd

    ftp = ftplib.FTP(host ,username,passw d)
    fd=open(filenam e,'rb')
    ftp.storbinary( 'STOR filename',fd)
    -------------------

    I am passing file name in cmd line arg. but I have no idea how to use "filename" variable value in ftp.storbinary( 'STOR filename',fd) ?





  • Diez B. Roggisch

    #2
    Re: Using variable in storbinary function of ftpilb module

    Arya, Manish Kumar wrote:
    Hi,
    >
    I am new to python.
    >
    I have written a simple code to upload a file via ftp to remote server
    >
    -------------
    import sys
    import ftplib
    host=sys.argv[1]
    username=sys.ar gv[2]
    passwd=sys.argv[3]
    filename=sys.ar gv[4]
    >
    print host,username,p asswd
    >
    ftp = ftplib.FTP(host ,username,passw d)
    fd=open(filenam e,'rb')
    ftp.storbinary( 'STOR filename',fd)
    -------------------
    >
    I am passing file name in cmd line arg. but I have no idea how to use
    "filename" variable value in ftp.storbinary( 'STOR filename',fd) ?
    ftp.storbinary( "STOR %s" % filename, fd)

    Diez

    Comment

    Working...