[英]Java file copy from one server to another
I want to copy one file from system1 to system2. 我想将一个文件从system1复制到system2。 both these system are in the same network. 这两个系统都在同一网络中。 the file is present in a shared folder in system1. 该文件位于system1的共享文件夹中。 i have a username and password to access that location. 我有一个用户名和密码可以访问该位置。 how can i write a javacode to perform this? 我如何编写一个Javacode来执行此操作?
Does your solution have to use plain Java? 您的解决方案是否必须使用纯Java? If not, it would be better to use existing file transfer utilities, like scp
if you're using *nix computers. 如果不是,最好使用现有的文件传输实用程序,例如,如果您正在使用* nix计算机,则使用scp
。
If the answer to my question is yes, then sockets are the way to go. 如果我的问题的答案是“是”,那么使用套接字就可以了。 Apache Commons libraries like net and io might also be useful. 诸如net和io之类的Apache Commons库也可能有用。
using sockets. 使用套接字。 connect to system1. 连接到system1。 copy file, connect to system 2. paste file. 复制文件,连接到系统2.粘贴文件。 voila. 瞧。
I know how to do it under *nix only. 我知道如何仅在* nix下执行此操作。 First you have to mount both shared folders. 首先,您必须安装两个共享文件夹。 That should do either system administrator of your computer or you can do it in your program via FUSE ("File system in user space") and appropriate Samba plugins. 这应该由您的计算机的系统管理员来完成,或者您可以通过FUSE(“用户空间中的文件系统”)和适当的Samba插件在程序中完成。 And then you can copy required files as usual. 然后,您可以照常复制所需的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.