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

2
Contributors
3
Replies
8
Views
9 Years
Discussion Span
Last Post by nirmalarasu
0

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>

0

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.