Python FTP script to upload file

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 12
Reputation: nirmalarasu is an unknown quantity at this point 
Solved Threads: 0
nirmalarasu nirmalarasu is offline Offline
Newbie Poster

Python FTP script to upload file

 
0
  #1
Feb 21st, 2008
Hi All,
Currently Iam writing python ftp script to upload a file to FTP Server.
The server where iam going to download a file expects the upload command in this format
"put <filename> flash"

I dont know how to send this same command in ftp session after login.

I have tried sendcmd call in this way, but its not working

comand='put send.bin flash'
ftp.sendcmd('STOR'+comand)


I need a suggestion from this group.


thanks
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 311
Reputation: BearofNH is on a distinguished road 
Solved Threads: 40
BearofNH's Avatar
BearofNH BearofNH is offline Offline
Posting Whiz

Re: Python FTP script to upload file

 
0
  #2
Feb 21st, 2008
put <filename> flash is an FTP client command that says "Take my local <filename> and copy it to the server as a file named flash".

So the correct call would be ftp.sendcmd('STOR flash')
It would then be up to you to follow that up with data from the local file <filename>
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 12
Reputation: nirmalarasu is an unknown quantity at this point 
Solved Threads: 0
nirmalarasu nirmalarasu is offline Offline
Newbie Poster

Re: Python FTP script to upload file

 
0
  #3
Feb 21st, 2008
Hi,
Still iam in loop.
Can you please explain , how to send the local file name after passing the command
"ftp.sendcmd('STOR flash')"

thanks for your response
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 12
Reputation: nirmalarasu is an unknown quantity at this point 
Solved Threads: 0
nirmalarasu nirmalarasu is offline Offline
Newbie Poster

Re: Python FTP script to upload file

 
0
  #4
Feb 21st, 2008
Yes I got the solution after few research.
Iam posting my solution for others .

import ftplib
import os

def upload(ftp, file):
ext = os.path.splitext(file)[1]
if ext in (".txt", ".htm", ".html"):
ftp.storlines("STOR flash " + file, open(file))
else:
print ftp.storbinary("STOR flash" + file, open(file, "rb"), 1024)


ftp = ftplib.FTP("**.**.**.**")
print ftp.login("ftp", "flash")
upload(ftp, "filename")
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC