Download a file from server in bash






















If these files already exist on your end, you are good to go. In reference to the above syntax rule, we can download our first file with the following approach from your desktop environment.

Maybe you have defined a non-standard port or you want to use a standard port on your Linux server environment for handling all remote file downloads. In this case, you should adhere to the following syntax rule:. You can still achieve remote file download with the following syntax.

When the file arrives, your script calculates each relevant detail and compares them to the values stored in the flag file. If you can't arrange this level of detail, at least generic flag file, per day-per file, OR per daily batch of files sent when all files are done could be followed with tests that compare the new files against a set of tests that makes sense for your particular situation, Then your defense is "we don't have complete control over the files, but we checked them for X,Y,Z and it passed those tests, that is why we loaded them".

While rsync could be good, I don't see how, given some of the scenarios mentioned, you'd ever be sure that it was safe to start loading the file, as rsync might start adding more data to the file. Reading through your script, if you can't get a detailed flag file from your source, you're on the right track. Glenn Jackman's solution looks to accomplish the same goal with less code. You could put that inside a scriptFile 'getRemotedata.

But it can get very complex when you try to cover all conditions. There are 3rd party tools that can manage file downloads, but we never had the budget to buy them, so I can't recommend any.

Welcome to StackOverflow S. The FTP protocol is not robust enough. It does not deal with atomicity and there's no way to know if a file is still being uploaded while you download it. If you need this functionality you need to investigate using rsync for both downloading AND uploading. How are we doing? Questions on Stack Overflow are expected to relate to programming within the scope defined by the community.

Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question. This question exists because it has historical significance, but it is not considered a good, on-topic question for this site , so please do not use it as evidence that you can ask similar questions here.

This question and its answers are frozen and cannot be changed. More info: help center. None of this I see mentioned in the answer. Show 4 more comments. Use lynx. Note lynx -source is closer to wget — Steven Penny. Hey, so this is a really late comment but how do you save the output of the telnet command to a file? Connected to www. I'm in a situation where I can only use telnet, I'm trying to make a chroot jail with the least frameworks possible.

This won't handle binary transfer files—it will fail on null bytes. Wildcard, i do not understand , i've edited with a binary file transfer example containing null bytes , can you point me what i'm missing? Wildcard, heheh, yeah that looks like it should work, since it reads the actual file data with cat. I'm not sure if that's cheating since it's not purely the shell , or a nice solution since cat is a standard tool, after all. But , you might want to add a note about why it works better than the other solutions here.

Wildcard, I added the pure bash solution too as an answer below. And yes, cheating or not, this is a valid solution and worth an upvote : — ilkkachu. Taking the " just Bash and nothing else " strictly, here's one adaptation of earlier answers Chris's , 's that does not call any external utilities not even standard ones but also works with binary files:!

Isn't echo a standalone -non shell- binary? Bash has echo and printf as builtins it needs a builtin printf to implement printf -v — ilkkachu. Considering that other answers don't respect the question requirement bash only , I think this is actually better than the lynx solution, as Perl is surely more likely to be preinstalled that Lynx. Based on Chris Snow recipe. Yecheng Fu Yecheng Fu 51 1 1 silver badge 3 3 bronze badges. It worked, But I found a concern, when I use this scripts, It keep wait several seconds when all data is read finished, this case not happen in Chris Snow answer, anyone could explain this?

I edit this answer with tag variable is correct set, it work well now. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.



0コメント

  • 1000 / 1000