Python Forum
upload from FTP(10.41.200.21) to FTP(10.41.101.25)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
upload from FTP(10.41.200.21) to FTP(10.41.101.25)
#1
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.close
please help me
Reply
#2
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!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020