Upload from FTP(12.50.100.21) to FTP(12.45.222.25)

Hello

It is definitely From FTP To FTP.

Copy from FTP(12.50.100.21) to FTP(12.45.222.25)

I need sample code.

Please give me a site with sample code for Copy from FTP(12.50.100.21) to FTP(12.45.222.25)

Please Help me

Try using the curl utility: https://curl.se/

Is there a sample code for transferring files from FTP to FTP using curl?

Please help me

curl is a command-line program. You do not use it to write code. Please try to read the information at the link that you were given.

For the task that you describe, there is no good reason to write your own program.

There is ftp in Pycurl

If you asking for code to be written consider paying a programmer.
If you are able to code then provide the code you have for feedback.

2 Likes

(post deleted by author)

You do not have a call to download the file.
Once you add that you should have all the pieces of logic you need.

You can transfer without saving to local.
But the code will be a lot more complex.

Suggest you get a simple version working first.
If that performs well enough use that version.

You can transfer without saving to local.
==> What method?

Please explain.

I can’t because I don’t know how to save it locally

Please

I assume you are reading ftplib — FTP protocol client — Python 3.12.2 documentation
You will see the retrbinary that allows the file to be saved locally.

Your Answer ) You can transfer without saving to local.
==> What method?

Please explain at least the rough concept.

Please help me…

It is a long time since I last looked at the FTP specs. But IIRC you can
connect to some server A, and ask it to transfer a file not to you but
to some server B. You may have to get server A to log in to server B
first. So in theory you can do this with FTP.

Just looking at the ftplib module (which I’ve never used) there isn’t
a method to directly do this. But maybe the sendcmd method can be
used:

The FTP specification itself is here:

Section 2.3 talks about the FTP model, with a nice diagram of the
entities in the system (server, filesystem, user - you).

There’s a distinction between the control connection, which is what you
establish when you set up a Python FTP instance, and the data connection
which is what is used to transfer files.

Below the fourth paragraph, which says:

 In another situation a user might wish to transfer files between
 two hosts, neither of which is a local host. The user sets up
 control connections to the two servers and then arranges for a
 data connection between them.  In this manner, control information
 is passed to the user-PI but data is transferred between the
 server data transfer processes.  Following is a model of this
 server-server interaction.

is Figure 2, showing 2 control connections, one for server A and once
for server B, with a data connection directly from server A to server B.

From Python you’d make 2 FTP instances, one connected to each server.
If I recall correctly, you tell server B (the receiving one) to listen
for a data conenction and then tell server A to make a data connection
and transfer the data.

The details of setting up the transfer are described in section 3.2 of
the spec: “ESTABLISHING DATA CONNECTIONS”.

I’ve never done this myself, I’ve only used FTP interactively to a
single server.

Cheers,
Cameron Simpson cs@cskk.id.au

That, I think, will not work these days with passive FTP being the default.

I think it may still work. IIRC the PASV command directs the server to
expect a connection from the client on port 20, like most client server
services, more firewall friendly. But I didn’t think it prevented the
server A to server B setup, it just changes the dynamic somehow. I’m
saying all this without having done it though.

It’s non-specific about port, so a properly-configured firewall and FTP server can pick any range of port numbers they like. However, the important distinction is that the IP address is governed by the server, not the client. The basic flow with active FTP is:

  1. Client establishes control connection to server.
  2. Client sends a PORT command, specifying an IPv4 address and port number using six integers. (I can’t remember how IPv6 plays into this but the OP’s working in IPv4 here.)
  3. Server establishes connection to the chosen IP/port.
  4. Client requests a transfer.

Whereas with passive, it’s:

  1. Client establishes control connection to server.
  2. Client sends PASV command. Server responds with six integers.
  3. Client establishes connection to the chosen IP/port.
  4. Client requests a transfer.

In other words, it’s the SERVER that picks which IP and port will be used for the transfer.

In order to conduct a “drop-ship” transfer, where a client establishes connections to two servers and initiates a transfer between them directly, one of the servers MUST be using active mode and one MUST be using passive mode. It doesn’t matter what the default is, as the client gets to ask both servers to select that mode, but there has to be one server able to do each aspect.

That said, though: The way that passive FTP is considered “more firewall friendly” is primarily at the client end. It’s not always easy for a client to listen on a port and receive data (when you’re behind NAT, for example). There certainly are some servers that will be tightly restricted in what outgoing connections they’re allowed to make, but far from all, and given that the two ends can be placed either way around, the odds are good that at least one of them will be compatible. So in theory, this can be done.

This is, however, nothing whatsoever to do with Python.

From documentation found here:
https://ftpext.readthedocs.io/en/latest/#users
and from here:

The last three entries are keyword defaults. So, I don’t think that you need to manually fill them.
The information that you need to fill are:

ftpext.ftpext.FTPExt(host, port, user, password)

Are the double asterisks required on both sides of the port number? I could not find in the documentation where that was stated as a requirement. If so, can you show where this is a requirement? Else, try removing them.

In the following line of code:

source.fxp_to("/test/test1.txt", target, "/test", 'I')

have you tried testing with the relative path versus partial path only? That is, have you tried entering the file path starting from the user directory as in:

"/Users/your_user_name/.../test/test1.txt"

Such that your code is:

import sys 
from ftpext.ftpext import FTPExt

source = FTPExt("100.20.75.35", 21, "user1", "abc")
target = FTPExt("200.12.62.15", 21, "user2", "def")

# upload(copy) "/test/test1.txt"  to  "/test"
source.fxp_to("/Users/user_name/.../test/test1.txt", target, "/test", 'I')

Since the error that is given is:

Give it try.

Even if I do what you said, I get the same error.
Please Help Me

Please note that you have to replace:

"/Users/user_name/.../test/test1.txt"

with your file’s actual path and not the one that I provided.

Do the same for your:

"/test"

Enter the entire relative path not just a file directory since the format is:

ftp1.fxp_to(path1, ftp2, path2)

The keyword here is: path

From the following thread:

They are using a partial relative path. It is not in the format that you stated above with the host id number. They might not have included the full path for privacy reasons, however.