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

Recommended Answers

All 3 Replies

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>

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

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")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.