| | |
Python FTP script to upload file
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 12
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Feb 2008
Posts: 12
Reputation:
Solved Threads: 0
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")
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")
![]() |
Other Threads in the Python Forum
- Previous Thread: Boxlets
- Next Thread: numpy + MA, problem with min and max on masked arrays
| Thread Tools | Search this Thread |
advanced aliased bash beginner bits calling casino changecolor class clear command convert corners count csv cturtle cursor def definedlines dictionary digital dynamic dynamically events examples external file float format frange function google gui hints homework i/o iframe import info input java line linux list lists loop matching mouse multiple number numbers obexftp output parsing path port prime programming projects py py2exe pygame pygtk python random rational raw_input recursion return scrolledtext signal singleton skinning stderr string strings subprocess table tails terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 valueerror variable voip web-scrape whileloop windows word wxpython





