Transferring the Contents of a Folder Using smbclient
I had the answer with me all along!! I was under the impression that mput
could only be used to transfer a directory, turns out that using mput *
inside a directory will copy all the files located within that directory!
cd /home/user/binaries
smbclient //ip.address/directory$ password -W domain -U username << ENDOFMYSMBCOMMANDS
prompt
put *
exit
ENDOFMYSMBCOMMANDS
Going to leave this here for anyone else who gets stumped on this like me!
smbclient script putting several files with variable
I got the solution be myself:
cd /directory/with/files/to/copy
#Set Variable
reports=$(ls *)
for i in $reports ; do
smbclient -U "srv\User"%pws //some/dir/bla/bla/bla << Commands
cd another/dir/etc
put $i
exit
Commands
done
Thanks!
Recursive file search for designated extension
Here are some fairly straightforward tweaks to your code to get it to fill an ArrayList
recursively. It isn't necessarily the most efficient way of doing this, as it gathers all filenames, and then throws away the ones that don't end with .mp4
, but it should give you a straightforward place to start building from.
private void btnFileCountActionPerformed(java.awt.event.ActionEvent evt) {
try (SMBClient client = new SMBClient()) {
try (Connection connection = client.connect(SERVER)) {
AuthenticationContext ac = new AuthenticationContext(USERNAME, PASSWORD.toCharArray(), WORKGROUP);
try (Session session = connection.authenticate(ac)) {
try (DiskShare share = (DiskShare) session.connectShare(SHARE)) {
List<String> files = new ArrayList<>();
listFiles(share, START_DIR, files);
files.removeIf(name -> !name.toLowerCase().endsWith(".mp4"));
files.forEach(System.out::println);
}
}
}
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
private void listFiles(DiskShare share, String path, Collection<String> files) {
List<String> dirs = new ArrayList<>();
String extPath = path.isEmpty() ? path : path + "\\";
for (FileIdBothDirectoryInformation f : share.list(path)) {
if ((f.getFileAttributes() & FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue()) != 0) {
if (!isSpecialDir(f.getFileName())) {
dirs.add(f.getFileName());
}
} else {
files.add(extPath + f.getFileName());
}
}
dirs.forEach(dir -> listFiles(share, extPath + dir, files));
}
private static boolean isSpecialDir(String fileName) {
return fileName.equals(".") || fileName.equals("..");
}
Related Topics
Access Permissions of /Dev/Mem
How to Access Team Foundation Server (Tfs) from Linux
A Running Bash Script Is Hung Somewhere. How to Find Out What Line It Is On
How to Recover or Change Oracle Sysdba Password
Linux Memory Reporting Discrepancy
Check If Vt-D/Iommu Has Been Enabled in The Bios/Uefi
Using <Linux/Types.H> in User Programs, or <Stdint.H> in Driver Module Code...Does It Matter
How to Realize a Diff Function
How to Expand Relative Paths in Shell Script
How to Ignore Some Differences in Diff Command
Parallel Make: Set -J8 as The Default Option
Is There Any Modern Review of Solutions to the 10000 Client/Sec Problem