[Tutor] FTPlib Module

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 3 Dec 2001 02:00:37 -0800 (PST)


On Sun, 2 Dec 2001, Cow wrote:

> I am currently learning to use the ftplib module, and i am getting most of it but i am running into a problem when i try to send a file.  Here is my code:
> 
> from ftplib import FTP
> 
> cow= FTP("127.0.0.1") #Pretend that that address is the address of a FTP
> cow.login()
> cow.cwd("/")
> cow.set_pasv(0)
> cow.transfercmd("STOR test1.txt")
> cow.close()
> 
> when i run the code, it sends the file to the sever, but there is nothing in the file (it is blank).  i am learning from this explanation:
> 
> transfercmd(cmd[, rest])
>  
> Initiate a transfer over the data connection. If the transfer is active, send a "EPRT" or "PORT" command and the transfer command specified by cmd, and accept the connection. If the server is passive, send a "EPSV" or "PASV" command, connect to it, and start the transfer command. Either way, return the socket for the connection. 
> 
> i get most of it, but when i actually use code, it only sends a blank file.  can someone please clear up how i can get my code to send the file with its data in it?

I took a closer look at:

    http://www.python.org/doc/current/lib/ftp-objects.html


You might want to use storbinary() or storlines() instead of
transfercmd(); I think that transfercmd() is meant for something
else.  See if:

###
cow.storlines("STOR test1.txt", open("test1.txt"))
###

works better for you.