How to Get Http Url of File Uploaded to Ftp Server

How to get HTTP URL of file uploaded to FTP server

There's no magical way to find out an HTTP URL of the file uploaded to an FTP server, that happens to share a file storage with the HTTP server.

It's a matter of configuration of both the FTP and HTTP servers; how do they map virtual HTTP and FTP paths to and from an actual file system paths.

The mapping can be completely virtual and undeterministic.


Having that said, most web hostings have some root both on FTP and HTTP, from where the mapping is deteministics.

If you connect to the FTP, you usually land in the root folder of the HTTP hosting, or immediately below it (there would be a subfolder like httpdocs or www that maps to the HTTP root).

If the FTP account is chrooted, the root folder will be / (or /httpdocs, etc).

If you have your own domain (www.example.com), then an FTP path like /index.html maps to https://www.example.com/index.html.

That's the most simple case. It can be a way more complicated. But that's something we cannot help you with. That's a question for your web hosting provider and/or administrator.

Java: Upload file from URL directly to FTP server with a library

There is support for both HTTP and at least limited FTP support through the standard API class java.net.URL. You have only restricted access to specific FTP features like setting the transfer mode, but in most cases it works.

If you add Apache Commons IO, you can use the IOUtils class to copy directly from the HTTP server to the FTP server:

InputStream in = new URL("http://host/path").openStream();
OutputStream out =
new URL("ftp://user:pass@host/path").openConnection().getOutputStream();

IOUtils.copy(in, out);

in.close();
out.close();

If you don't want to add a dependency on Commons IO, you just have to write a few lines to copy the data without 3rd party library support:

byte[] buffer = new byte[16384];
int r = 0;
while ((r=in.read(buffer))>=0) {
out.write(buffer, 0, r);
}

Download file from url and upload into ftp

I think your problem is that your url is missing the file name. If I remember correctly you must pass the file name in the URL. So it would look something like this:

"ftp://192.168.1.1/SampleFiles/file.txt"

Download a giant file with HTTP and upload to FTP server without storing it

Use requests module to obtain a file-like object representing the HTTP download and use it with ftplib FTP.storbinary:

from ftplib import FTP
import requests

url = "https://www.example.com/file.zip"
r = requests.get(url, stream=True)
ftp = FTP(host, user, passwd)
ftp.storbinary("STOR /ftp/path/file.zip", r.raw)

How to transfer a file from url to ftp using java?

  1. Would require you to read the entire file referenced by the URL before you can send it to the ftp server. If the file is really large, you may need to write it to a temporary file when you read from the URL connection, then read from the temporary file when you send to the FTP server. With this method, keeping the reading from the URL and the writing to the FTP server separate, you can handle the errors separately. For example, if the URL connection throws exceptions, you can handle that accordingly, and perhaps retry the request. You can ensure you have the complete file before any communication with the FTP server is attempted.

  2. You can do this if you've established the input and output streams and are ready to read from and write to them. This means you've already done all the protocol stull, and on the FTP server, that means telling it that you want to upload a file, where you want to upload it, and what the file's name is. Then you can simply read from the URL input stream and write that block to the FTP's output stream. Because this is streamed, if the communication between you and the webserver, or you and the FTP server gets interrupted. You'll probably have to restart everything from the beginning.

Either way is acceptable.

How to make CkFinder generate HTTP URLs for uploaded file when using FTP backend FileSystem in CkFinder 3 ASP.NET

The problem was within CkFinder itself. CkSource released an update 3.4.2 and now the problem is fixed.

The following configuration option is required for FTP back-end to translate ftp url into http: <option name="baseUrl" value="http://example.com/folder/subfolder/" />

I have also set the useProxyCommand to false:

<backend name="default" adapter="ftp" useProxyCommand="false">



Related Topics



Leave a reply



Submit