Mike
Mike

Reputation: 2339

Create file on another server

How would I create a file in another windows server? The server has a username, and password, ip address and specific directory.

Upvotes: 0

Views: 1047

Answers (2)

Marsellus Wallace
Marsellus Wallace

Reputation: 18601

SAMBA! Braziiillll, Braziiiiiiillll!

Something like this:

String userPass = "username:password";
String filePath = "smb://ip_address/shared_folder/file_name";

NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication(userPass);
SmbFile smbFile = new SmbFile(filePath, authentication);
SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(smbFile);
PrintStream printStream = new PrintStream(smbFileOutputStream);
//You should be good from this point on...             

NOTE: The destination folder needs to be shared first!

Upvotes: 1

Rafael Cordones
Rafael Cordones

Reputation: 831

As @orm already points out, this is answered already here FTP upload via sockets

Basically, you could reuse an existing library like Apache Commons Net to do it. For the specifics of using the FTP client have a look at the documentation for the class FTPClient class.

Upvotes: 0

Related Questions