upload from FTP(10.41.200.21) to FTP(10.41.101.25) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: upload from FTP(10.41.200.21) to FTP(10.41.101.25) (/thread-41927.html) |
upload from FTP(10.41.200.21) to FTP(10.41.101.25) - anna17 - Apr-10-2024 Hello. How do I upload from FTP(10.41.200.21) to FTP(10.41.101.25) using python? import ftplib import os filename = "image.tif" ftp_send=ftplib.FTP() ftp_send.connect("10.41.200.21",21) ftp_send.login("receive","abcd") ftp_send.cwd("test_receive") ftp_receive=ftplib.FTP() ftp_receive.connect("10.41.101.25",21) ftp_receive.login("send","abcd") ftp_receive.cwd("test_send") os.chdir(r"D:/") <===== It must be an FTP folder path, not a local folder. myfile = open(filename,'rb') ftp_send.storbinary('STOR ' + filename, myfile ) myfile.close() ftp_send.closeplease help me RE: upload from FTP(10.41.200.21) to FTP(10.41.101.25) - Pedroski55 - Apr-13-2024 Just a suggestion, I have never done this and I have no intranet to try this on. I think you need to download the file from the first ftp address to your local machine, then upload the file from your local machine to the other ftp address. You must be working from somewhere! from ftplib import FTP # get a file from 10.41.200.21 ftp = FTP('10.41.200.21') ftp.login('USERNAME','PASSWORD') ftp.cwd('/where/my/file/is/') # list current files & directories ftp.dir() # where are you working from? Where to put the file? with open('/my/local/machine/myfile.sth', 'wb') as fp: ftp.retrbinary('RETR afile.sth', fp.write) ftp.quit() # put a file in 10.41.101.25 ftp2 = FTP('10.41.101.25') ftp2.login('USERNAME','PASSWORD') ftp2.cwd('/where/my/file/goes/') # local file name you want to upload # where are you working from? filename = '/my/local/machine/myfile.sth' with open(filename, "rb") as file: # use FTP's STOR command to upload the file ftp2.storbinary(f"STOR {filename}", file) # list current files & directories ftp2.dir() ftp2.quit()Maybe you can miss the step where you save the file on your local machine and directly upload the binary to ftp2? Try it! |